From: Dan Doel Date: 2003-08-13T11:34:06+09:00 Subject: Re: hash default value Christoph R. wrote: > or if you like puzzles > > --- > body = proc {|hsh,key| hsh[key] = Hash.new &body } > autovhsh = Hash.new &body > > autovhsh[1][2][3] = 4 > p autovhsh[1][2][3] # => 4 > --- Like puzzles, do you? $y = proc { |f| proc { |x| f[x[x]] }[proc { |x| proc { |z,w| f[x[x]][z,w] } }] } def y(f) proc do |z, w| f[y(f)][z, w] end end gen2 = proc { |f| proc { |h, k| h[k] = Hash.new &f } } h1 = Hash.new &(y(gen2)) h2 = Hash.new &($y[gen2]) p "Using h1" p h1['1'] p h1['a']['b']['c'] p "Using h2" p h2['1'] p h2['a']['b']['c']['d'][4] Fun-ctional programming with Ruby. - Dan