Iterate over an array with the index?

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... :wink:

Thanks
Josh

Won't each_with_index suffice?

Joshua Muheim wrote:

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... :wink:

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...? :wink:

Thanks anyway :slight_smile: