Forum: Ruby on Rails Quick Ruby Array question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A73f446eaaf56db0aeaa578aa373989b?d=identicon&s=25 Terry Donaghe (Guest)
on 2007-05-07 04:58
(Received via mailing list)
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
8bc543795b502900b5333aea73ad5533?d=identicon&s=25 Eden Li (edenli)
on 2007-05-07 05:22
(Received via mailing list)
Yes, although #each is more rubyish:

@cart.line_items.each do |line_item|
  # do stuff
end
A73f446eaaf56db0aeaa578aa373989b?d=identicon&s=25 Terry Donaghe (Guest)
on 2007-05-07 05:50
(Received via mailing list)
Thanks eden!

On 5/6/07, eden li <eden.li@gmail.com> wrote:
> >
> >
> > --
> > Terry (TAD) Donaghehttp://tadspot.tumblr.com
>
>
> >
>


--
Terry (TAD) Donaghe
http://tadspot.tumblr.com
588ab1c0a5610a7e160a3b101abb91e6?d=identicon&s=25 MichaelLatta (Guest)
on 2007-05-07 17:07
(Received via mailing list)
And if you need the indexes:

@card.line_items.each_with_index do | line_item, index |


Michael
This topic is locked and can not be replied to.