0
In Ruby there's a method each_cons, which can be used to iterate over consecutive groups of a given size. For example,
irb(main):001:0> [4, 7, 6, 1, 0, 3].each_cons(2) { |x| p x }
[4, 7]
[7, 6]
[6, 1]
[1, 0]
[0, 3]
=> nil
Here we're selecting and printing each consecutive pair of elements from...