From: Daniel Martin Date: 2007-06-12T21:21:06+09:00 Subject: Re: how to make a[2][2][3]=4 work? In addition to what's already been posted, there's this, which doesn't require any extra variables or methods: a = Hash.new{|h,k| h[k]=Hash.new &h.default_proc} gz zz writes: > a[2][1]=2 > a[2][2][3]=4 > a[3][1][1][1]=1 > p a irb(main):001:0> a = Hash.new{|h,k| h[k]=Hash.new &h.default_proc} => {} irb(main):002:0> a[2][1]=2 => 2 irb(main):003:0> a[2][2][3]=4 => 4 irb(main):004:0> a[3][1][1][1]=1 => 1 irb(main):005:0> p a {2=>{1=>2, 2=>{3=>4}}, 3=>{1=>{1=>{1=>1}}}} => nil -- s=%q( Daniel Martin -- martin@snowplow.org puts "s=%q(#{s})",s.to_a.last ) puts "s=%q(#{s})",s.to_a.last