From: Brian Candler Date: 2003-04-25T16:25:52+09:00 Subject: Re: Hashes and Enumerable#each_with_index On Fri, Apr 25, 2003 at 07:26:01AM +0900, Ryan Pavlik wrote: > OK, looking at the archives I know this was discussed a few years ago, > but there seems to be no real conclusion or improvement since then. > > The problem: Hash#each_with_index returns an index that is not usable > to address the hash. That is, given the following: > > h = Hash.new > h.each_with_index { > | o, i | > ... > } > > i is not defined such that h[i] == o, which is both misleading and > seemingly useless. (This behavior, as per the previous discussion, can > be achieved with h.to_a.each_with_index.) Or indeed just 'h.each' (if you replace |o,i| with |i,o|) It did seem a bit strange to me at first that the methods don't really line up: Array#each <=> Hash#each_value Array#each_with_index <=> Hash#each (but with args reversed) Regards, Brian.