Over a million developers have joined DZone.

Each_slice

·

require 'enumerator'

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

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}