Limit Split
I've only ever used Ruby's String#split
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 The Rails 4 Way) is for splitting a name into first and last names.
This really simplifies the code that is needed to make the following example work:
Last updated