From: Tim Bates Date: 2002-11-27T23:35:58+09:00 Subject: Re: each_with_index & collect_with_index? On Wed, 27 Nov 2002 11:20 pm, dblack@candle.superlink.net wrote: > Now, somewhere behind the scenes (in my version), you're adding the > #iteration method to the actual objects being iterated. I think this has been suggested before, but... why not use something like Enumerable.index? But here's the new bit, just have it refer to the innermost iterator. You can assign it to something if you want nested iterators, eg: arr.each do |e| outerindex = Enumerable.index arr.each do |f| innerindex = Enumerable.index ... end end And perhaps Enumerable.index == nil if we're not inside an iterator. Only problem I can see is if I were to define my own iterator using 'yield', how would I indicate that I want Enumerable.index to return something sensible? Tim Bates -- tim@bates.id.au