I have an array with pairs of numbers:
a = [[4, 6], [3, 0], [0, 0]]
When I do:
a.each do |x|
puts x
done
I get a flattened set of values:
4
6
3
0
0
0
What I want is for the values to remain in pairs:
[4,6]
[3,0]
[0,0]
Ideally, I'd like to iterate with an Enumerator
, because I'd like to make use of #peek
during the loop processing.
I've found that:
e = a.each
loop do
puts e.next
end
gives the same output as the flattened example above, with an additional nil
at the end.
Is there a way to loop while preserve the grouping of the array in pairs?