From: ara.t.howard@... Date: 2006-07-13T06:27:33+09:00 Subject: Re: multiple level hash assignment equivalence to perl On Thu, 13 Jul 2006, Joel VanderWerf wrote: > don mc wrote: >> Is there a succinct way in ruby to do a multiple level hash assignement? I >> am more >> used to perl, which you can do something like >> >> >> $hp->{level1}->{level2} = 3 >> >> even if the first and second level had never existed below. > > There's an autovivification trick, using the default proc of a hash (see ri > default_proc): > > irb(main):002:0> pr = proc {|h,k| h[k]=Hash.new(&pr) } > => # > irb(main):003:0> h = Hash.new(&pr) ^^ ^^ nice! my approach is slightly more verbose. -a -- suffering increases your inner strength. also, the wishing for suffering makes the suffering disappear. - h.h. the 14th dali lama