On Mon, Dec 5, 2011 at 5:34 PM, Adam Prescott <adam / aprescott.com> wrote:
> On Mon, Dec 5, 2011 at 16:28, Chad Perrin <code / apotheon.net> wrote:
>
>> =A0 =A0>> foo =3D Hash.new( Hash.new )
>> =A0 =A0=3D> {}
>> =A0 =A0>> foo[3][2] =3D true
>> =A0 =A0=3D> true
>> =A0 =A0>> foo
>> =A0 =A0=3D> {}
>>
>
> This is odd.

From the docs:

http://ruby-doc.org/core-1.9.3/Hash.html#method-c-new

Returns a new, empty hash. If this hash is subsequently accessed by a
key that doesn=92t correspond to a hash entry, the value returned
depends on the style of new used to create the hash. In the first
form, the access returns nil. If obj is specified, this single object
will be used for all default values. If a block is specified, it will
be called with the hash object and the key, and should return the
default value. It is the block=92s responsibility to store the value in
the hash if required.

The only thing that the second form does is return the same object for
all missing keys. It doesn't store it in the hash.

Jesus.