Ruby Enumerable#first takes an argument – duh

This may be a little stupid but I just found that ruby’s Enumerable#first takes an argument.

Get the first 5 elements

arr.first(5)

That’s a little handiness that I should have known about long ago. If you also didn’t know, now you do.

For more, read about ruby Enumerable.

Advertisements

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