In code like: for line_item in @cart.line_items #Do Stuff end Am I guaranteed to traverse the array from the first element successively through each index number from first to last? If not, what''s the proper ruby way to do that? Thanks! -- Terry (TAD) Donaghe http://tadspot.tumblr.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 -~----------~----~----~----~------~----~------~--~---
Yes, although #each is more rubyish: @cart.line_items.each do |line_item| # do stuff end On May 7, 10:57 am, "Terry Donaghe" <terry.dona...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In code like: > > for line_item in @cart.line_items > #Do Stuff > end > > Am I guaranteed to traverse the array from the first element successively > through each index number from first to last? If not, what''s the proper > ruby way to do that? > > Thanks! > > -- > Terry (TAD) Donaghehttp://tadspot.tumblr.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 -~----------~----~----~----~------~----~------~--~---
Thanks eden! On 5/6/07, eden li <eden.li-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Yes, although #each is more rubyish: > > @cart.line_items.each do |line_item| > # do stuff > end > > On May 7, 10:57 am, "Terry Donaghe" <terry.dona...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > In code like: > > > > for line_item in @cart.line_items > > #Do Stuff > > end > > > > Am I guaranteed to traverse the array from the first element > successively > > through each index number from first to last? If not, what''s the proper > > ruby way to do that? > > > > Thanks! > > > > -- > > Terry (TAD) Donaghehttp://tadspot.tumblr.com > > > > >-- Terry (TAD) Donaghe http://tadspot.tumblr.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 -~----------~----~----~----~------~----~------~--~---
And if you need the indexes: @card.line_items.each_with_index do | line_item, index | Michael On May 6, 8:49 pm, "Terry Donaghe" <terry.dona...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks eden! > > On 5/6/07, eden li <eden...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Yes, although #each is more rubyish: > > > @cart.line_items.each do |line_item| > > # do stuff > > end > > > On May 7, 10:57 am, "Terry Donaghe" <terry.dona...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > In code like: > > > > for line_item in @cart.line_items > > > #Do Stuff > > > end > > > > Am I guaranteed to traverse the array from the first element > > successively > > > through each index number from first to last? If not, what''s the proper > > > ruby way to do that? > > > > Thanks! > > > > -- > > > Terry (TAD) Donaghehttp://tadspot.tumblr.com > > -- > Terry (TAD) Donaghehttp://tadspot.tumblr.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 -~----------~----~----~----~------~----~------~--~---