From: Phrogz Date: 2009-02-16T08:03:23+09:00 Subject: Re: Iterating a changing Hash under 1.9.1 On Feb 15, 2:55 pm, Charles Oliver Nutter wrote: > Phrogz wrote: > > The following code shows that Hash#each under 1.9.1p0 does not iterate > > over keys added during iteration: > >   a = [ 1, 2, 3 ]; h = { 0=>0 } > >   h.each{ |k,v| h[a[k]] = a[k] } > >   p h > >   #=> {0=>0, 1=>1} > > In this case, you're only reassigning the same keys over and over again. > Since they're just being reassigned, they don't get pushed to the end of > the iteration and you don't loop forever. I think you're wrong. Initial state: { 0=>0 } First loop: k is 0, a[0] is 1, assign h[1]=>1 A brand new key/value has been inserted to the hash this point. If #each then covered the next key/value pair: Second loop: k is 1, a[1] is 2, assign h[2]=>2 (and so on)