From: Adam Prescott Date: 2011-12-06T01:34:39+09:00 Subject: Re: black magical hash element vivification --f46d04479701fbeeac04b35ae4a2 Content-Type: text/plain; charset=UTF-8 On Mon, Dec 5, 2011 at 16:28, Chad Perrin wrote: > >> foo = Hash.new( Hash.new ) > => {} > >> foo[3][2] = true > => true > >> foo > => {} > This is odd. > >> foo[3] > => {2=>true} > >> foo[2] > => {2=>true} > This isn't. Hash.new(Hash.new) != Hash.new { |h, k| h[k] = Hash.new }. The left hand side uses the same object for each default access, hence f = Hash.new([]); f[1] << 1; f[2].include?(1) == true. The right hand-side behaves as you expect for this part. >> foo > => {} > Again, definitely odd! :) foo.rehash didn't fix anything. Looks like a bug to me? --f46d04479701fbeeac04b35ae4a2--