I want to divide a string into chunks of unequal size (as given by lens). My code works, but does not feel like idiomatic Ruby. Any suggestions?
s = "red 4827spoon jimmy john "
lens = [6, 4, 12, 13]
i = 0
row = lens.collect {|len|
i += len
s[i-len, len].strip
}
Gives
["red", "4827", "spoon", "jimmy john"]
1 Answer