From: Robert Klemme Date: 2003-10-05T02:55:21+09:00 Subject: Re: hash of hashes "Paul Argentoff" schrieb im Newsbeitrag news:200310031517.45708.argentoff@rtelekom.ru... > On Friday 03 October 2003 14:48, Emmanuel Touzery wrote: > > > not sure i understand your question. does this help you? > > > > irb(main):001:0> a = {} > > {} > > irb(main):002:0> a["blue"] = {} > > {} > > irb(main):003:0> a["blue"]["red"] = 3 > > 3 > > irb(main):004:0> a["blue"] > > {"red"=>3} > > irb(main):005:0> a["blue"]["red"] > > 3 > > irb(main):006:0> > > Here is my example: > > irb(main):008:0> a = Hash.new(Hash.new(Array.new(2,0))) > => {} > irb(main):009:0> a['foo']['bar'][1] = 2 > => 2 > irb(main):010:0> a['foo']['bar'] > => [0, 2] > irb(main):011:0> a.keys > => [] > irb(main):012:0> > > After this I can't iterate over a's keys -- what I've written the whole mess > for :( That's because the form Hash.new( obj ) just replaces the nil return value for keys that are not found. In your example you have a hash that returns a hash for unknown keys that in turn returns an array for unknown keys. You definitely need the block form. Or you have to wrap or sub class the hash if you want to use pre 1.8 ruby versions. Regards robert