From: Kaya Aykut on 28 Jul 2010 18:24 Hello all, newbie here. 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. Thanks in advance :-) -- Posted via http://www.ruby-forum.com/.
From: James Harrison on 28 Jul 2010 18:41 > > 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
From: Nicholas Orr on 28 Jul 2010 18:43 [Note: parts of this message were removed to make it a legal post.] or use each_with_index http://ruby-doc.org/core/classes/Enumerable.html#M003137 On Thu, Jul 29, 2010 at 8:41 AM, James Harrison <oscartheduck(a)gmail.com>wrote: > > > > 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 > >
From: BruceL on 30 Jul 2010 11:36 On Jul 28, 6:24 pm, Kaya Aykut <kaya.ay...(a)gmail.com> wrote: dummy_array.each_index do |i| a = array[i] end
|
Pages: 1 Prev: rubyw, RuntimeError, capturing the stack, FXRuby Next: [ANN] hitimes 1.1.0 Released |