From: James Harrison Date: 2010-07-29T07:41:32+09:00 Subject: Re: how to determine array element number in a each loop > > The title is quite self explanatory: I am in > > dummy_array.each do |a| > #code here > end > > and I want to know which element (the number n in nth element) of the > dummy_array. > You could just put a counting variable in there: i = 0 > dummy_array.each do |a| i = i+1 > #code here > end You can also use each_index on the array if you'd like. http://ruby-doc.org/core/classes/Array.html#M002174