Quick Ruby Array question

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

Yes, although #each is more rubyish:

@cart.line_items.each do |line_item|

do stuff

end

Thanks eden!

On 5/6/07, eden li [email protected] wrote:


Terry (TAD) Donaghehttp://tadspot.tumblr.com


Terry (TAD) Donaghe

And if you need the indexes:

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

Michael

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs