What is the easiest way to convert a ruby array to an array of consecutive pairs of its elements?
I mean:
x = [:a, :b, :c, :d]
Expe
Use Enumerable#each_slice:
y = x.each_slice(2).to_a #=> [[:a, :b], [:c, :d]] [0, 1, 2, 3, 4, 5].each_slice(2).to_a #=> [[0, 1], [2, 3], [4, 5]]
Hash[*[:a, :b, :c, :d]].to_a