Ruby Quicktips Logo

Ruby Quicktips

Random Ruby and Rails tips.
This blog is dedicated to deliver short, interesting and practical tidbits of the Ruby language and Ruby on Rails framework. Read more...

Your submissions are more than welcome!
Dec 14 ’10

Array#first and Array#last parameters

Did you know you can pass a number parameter to Array#first and Array#last?

x = [1,2,3,4,5,6,7,8,9,10]

x.first 5 
=> [1,2,3,4,5] 

x.last 2 
=> [9,10] 

This tip was submitted by Alfred Nagy.

20 notes 0 comments

  1. rubyloveinfo reblogged this from rubyquicktips
  2. kimooz reblogged this from rubyquicktips
  3. smurfeater reblogged this from rubyquicktips
  4. Alfred Nagy submitted this to rubyquicktips

Comments

You can use HTML tags for formatting. Wrap code in <code> tags and multiple lines of code in <pre><code> tags.

blog comments powered by Disqus