Hi, Is there any ruby function to fetch first five elements from array for eg:a=[134,374,878,98,763,47,5669] i want to get only first five i.e 134,374,878,98,763 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Greetings -- ~$ irb>> a=(1 .. 10).to_a=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]>> a[0 .. 4]=> [1, 2, 3, 4, 5]>>Hope that helps... On Wed, 2008-07-16 at 06:55 +0200, Pragash Mr. wrote:> Hi, > Is there any ruby function to fetch first five elements from array > > for eg:a=[134,374,878,98,763,47,5669] > i want to get only first five i.e 134,374,878,98,763--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
err, make that a[0 ... 4] or a[0 .. 3] On Wed, 2008-07-16 at 06:55 +0200, Pragash Mr. wrote:> Hi, > Is there any ruby function to fetch first five elements from array > > for eg:a=[134,374,878,98,763,47,5669] > i want to get only first five i.e 134,374,878,98,763--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
[134, 374, 878, 98, 763, 47, 5669].first(5) :) Needs a recent-ish Ruby to work. Tor Erik -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You can also do a[0,5] Anna Lissa On Wed, Jul 16, 2008 at 3:29 AM, Tor Erik Linnerud < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > [134, 374, 878, 98, 763, 47, 5669].first(5) :) > > Needs a recent-ish Ruby to work. > > Tor Erik > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---