each_slice
1 2 require 'enumerator' 3 4 (1..10).each_slice(2) { |n| p n } 5 # [1, 2] 6 # [3, 4] 7 # [5, 6] 8 # [7, 8] 9 # [9, 10]
DZone Snippets > nemostultae > array
12876 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Daniel www.generalconsumption.org
1 2 require 'enumerator' 3 4 (1..10).each_slice(2) { |n| p n } 5 # [1, 2] 6 # [3, 4] 7 # [5, 6] 8 # [7, 8] 9 # [9, 10]