Hi all
Is there a method to iterate over an array with the index? Something
like
my_array.each_with_index do |obj, index|
…
end
Just couldn’t find such a method… maybe I worked too much today…
Thanks
Josh
Hi all
Is there a method to iterate over an array with the index? Something
like
my_array.each_with_index do |obj, index|
…
end
Just couldn’t find such a method… maybe I worked too much today…
Thanks
Josh
On Sep 27, 1:36 am, Joshua M. [email protected]
wrote:
Thanks
JoshPosted viahttp://www.ruby-forum.com/.
Won’t each_with_index suffice?
Joshua M. wrote:
Hi all
Is there a method to iterate over an array with the index? Something
likemy_array.each_with_index do |obj, index|
…
endJust couldn’t find such a method… maybe I worked too much today…
Thanks
Josh
Hi Josh,
I agree that you worked too much today. Ruby’s Enumerable class has that
exact method.
[1, 2].respond_to?(:each_with_index)
=> true
Peace.
What was I thinking…?
Thanks anyway
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs