Limit Split
Last updated
Was this helpful?
Last updated
Was this helpful?
I've only ever used Ruby's with the delimiter argument (e.g. "this string has spaces".split(" ")
). However, this method has another argument you can specify; the limit
argument. With limit
, you can limit the number of times that the split happens.
There are surely many use cases, but one that stands out (from ) is for splitting a name into first and last names.
This really simplifies the code that is needed to make the following example work: