From: "Jesús Gabriel y Galán" Date: 2009-01-08T00:44:23+09:00 Subject: Re: Default values of hashes On Sun, Jan 4, 2009 at 2:37 PM, David A. Black wrote: > Hi -- > It's come up before; here's the solution I seem to recall: > > hproc = lambda {|h,k| h[k] = Hash.new(&hproc) } > hash = Hash.new(&hproc) > > hash[1][2][3] = 4 > p hash # {1=>{2=>{3=>4}}} Hi, Another version, without the intermediate lambda: irb(main):009:0> hash = Hash.new{|h,k| h[k] = Hash.new(&h.default_proc)} => {} irb(main):010:0> hash[1][2][3] = 4 => 4 irb(main):011:0> hash => {1=>{2=>{3=>4}}} Jesus.