From: Yusuke ENDOH Date: 2009-02-04T22:56:11+09:00 Subject: [ruby-core:21833] Re: 1.9 Bug Report Hi, 2009/2/4 Yehuda Katz : > When going through the RubySpecs for 1.9, I found that the following code > will hang the 1.9 VM: > > hsh = {1 => 2, 3 => 4, 5 => 6} > hsh.merge!(hsh) {|x, y, z| p [x, y, z]; hsh.shift; true } > p hsh > > The output in 1.8: > [5, 6, 6] > [1, 2, 2] > [3, 4, 4] > {3=>true} It's by chance that your code stops in 1.8, I think. In 1.8, an iteration order of hash is unspecified. So, when you insert an new key into a hash during its iteration, it is also unspecified whether the new key will appear on the remaining iteration or not. On the other hand, 1.9's hash is insertion-ordered. An newly inserted key will certainly appear at the last of the order. So inserting new keys during an iteration makes the iteration infinite loop. $ cat test.rb h = {1 => nil, 2 => nil} h.each_key {|x| p [h, x]; h.delete(x); h[x] = nil } $ ruby18 test.rb [{1=>nil, 2=>nil}, 1] [{1=>nil, 2=>nil}, 2] $ ruby19 test.rb [{1=>nil, 2=>nil}, 1] [{2=>nil, 1=>nil}, 2] [{1=>nil, 2=>nil}, 1] [{2=>nil, 1=>nil}, 2] [{1=>nil, 2=>nil}, 1] [{2=>nil, 1=>nil}, 2] [{1=>nil, 2=>nil}, 1] [{2=>nil, 1=>nil}, 2] [{1=>nil, 2=>nil}, 1] [{2=>nil, 1=>nil}, 2] ... -- Yusuke ENDOH