Programming-Idioms

History of Idiom 163 > diff from v1 to v2

Edit summary for version 2 :
New Ruby implementation by user [steenslag]

Version 1

Version 2

Idiom #163 Print list elements by group of 2

Print all the list elements, two by two, assuming list length is even.

Idiom #163 Print list elements by group of 2

Print all the list elements, two by two, assuming list length is even.

Code
list.each_slice(2){|slice| p slice}
Demo URL
http://ideone.com/IpHiJ1