Great!

h =3D Hash.new {|h,k| h[k] =3D Hash.new(&h.default_proc)}

To understand, I've had to put a (unecessary) parenthesis.

h =3D Hash.new {|h,k| h[k] =3D Hash.new(&(h.default_proc))}

They are the same, aren't they?

It passes the default_proc of h as a block (&) creating the recursion.

I haven't seen this form before!

Congratulations.

Abinoam Jr.


On Tue, Dec 10, 2013 at 7:07 AM, Jes=FAs Gabriel y Gal=E1n
<jgabrielygalan / gmail.com> wrote:
> On Tue, Dec 10, 2013 at 7:49 AM, selvag selvag <lists / ruby-forum.com> wro=
te:
>> #!/usr/bin/ruby
>> #hash_of_hash.rb
>>
>> list=3D{"app1"=3D>101,"app2"=3D>104,"app3"=3D>109,"app4"=3D>123}
>>
>> h=3DHash.new{ |h,id| h[id]=3DHash.new{ |h,dt| h[dt]=3D{} }}
>> h["company"]["products"]=3Dlist
>> puts h
>>
>> # edit this code if you've much easier format than this one.
>> # output should be same.
>
> Arbitrary nesting:
>
> 1.9.3-p448 :001 > h =3D Hash.new {|h,k| h[k] =3D Hash.new(&h.default_proc=
)}
>  =3D> {}
> 1.9.3-p448 :002 > h[1][2][3][4] =3D true
>  =3D> true
> 1.9.3-p448 :003 > h
>  =3D> {1=3D>{2=3D>{3=3D>{4=3D>true}}}}
>
> Jesus.