Skip to content
Tags

,

each_slice

January 5, 2012

#each_slice is defined on an enumerable and splits it into a slice of 3. a block can be passed to it so that it performs an action on each of those slices.

ruby-1.9.2-p290 :003 > [1, 2, 3, 4, 5, 6, 7, 8, 9].each_slice(3){|a| puts "#{a}"}
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
=> nil

http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-each_slice


Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: