Say I have an array:
s = ["Abc", 123, "Abc", 123, "Abc", 123, "Abc", 123, "Abc", 123]
What would be the best way to turn it into
array = [["Abc",123]["Abc",123]["Abc",123]["Abc",123]["Abc",123]
Say I have an array:
s = ["Abc", 123, "Abc", 123, "Abc", 123, "Abc", 123, "Abc", 123]
What would be the best way to turn it into
array = [["Abc",123]["Abc",123]["Abc",123]["Abc",123]["Abc",123]
each_slice(n) { ... } → nil
each_slice(n) → an_enumerator
Iterates the given block for each slice ofn
elements. If no block is given, returns an enumerator.
So you'd say:
s.each_slice(2).to_a
or
s.each_slice(2).entries