DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Each_slice

09.30.2005
| 5626 views |
  • submit to reddit
        
require 'enumerator'

(1..10).each_slice(2) { |n| p n }
# [1, 2]
# [3, 4]
# [5, 6]
# [7, 8]
# [9, 10]