Possible Duplicate:
How to split (chunk) a Ruby array into parts of X elements?
I would like to split an array into an array of sub-arrays.
For example,
big_array = (0...6).to_a
How can we cut this big array into an array of arrays (of a max length of 2 items) such as:
arrays = big_array.split_please(2)
Where...
arrays # => [ [0, 1],
[2, 3],
[4, 5] ]
Note: I ask this question, 'cause in order to do it, I'm currently coding like this:
arrays = [
big_array[0..1],
big_array[2..3],
big_array[4..5]
]
...which is so ugly. And very unmaintainable code, when big_array.length > 100
.