From: sto.mar@... Date: 2013-06-25T00:41:53+09:00 Subject: Re: Confusin with Hash default Am 23.06.2013 08:17, schrieb Love U Ruby: > I was doing some practice and play with Hash default value as written in > the documentation. > > > h = Hash.new([]) > h[:a] << 2 > h[:a] << 3 > h[:a] # => [2, 3] > > Till above is perfect. > > h # => {} > > Why the Hash h is empty hash here? > > h[:b] << 2 > h[:b] # => [2, 3, 2] > > How h[:b] is `[2, 3, 2]` instead of only `[2]` ? The documentation is very specific about the difference between Hash.new() and Hash.new {}, providing in the first case a **single** default object, whereas in the second case a fresh object is returned. You should study the given examples. --