Say you have this array:
arr = w|one two three|
How can I iterate over it by having two consecutive elements as block arguments like this:
1st cycle: |nil, 'one'|
2nd cycle: |'one', 'two'|
3rd cycle: |'two', 'three'|
Sofar I came only with this:
arr.each_index { |i| [i - 1 < 0 ? nil: arr[i - 1], arr[i]] }
Any better solutions? Is there something like each(n)
?