From: Rick DeNatale Date: 2009-06-02T08:58:14+09:00 Subject: Re: counting .each On Mon, Jun 1, 2009 at 7:06 PM, Mk 27 wrote: > Is there some equivalent to file.lineno when using array.each?  Eg, if I > am iterating thru an array of strings searching for a pattern, and I > want to save the current array index, do I have to do this: > > count = 0 > array.each { |e| >    finds.push count if e =~ /pattern/ >    count += 1 > } > > or is there a "array.currentindex"?  I guess I could use each_index... array.each_with_index do | e, count| finds.push count if e =~ /pattern/ end -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale