From: ts Date: 2002-03-27T23:20:14+09:00 Subject: Re: Hash.new(Hash.new) doesn't use Hash.new as default value >>>>> "J" == Jonas Delfs writes: J> If it's no bug, I think it's a bug in documentation. - and not a very logic J> behavior. No, it's not a bug nor a bug in the documentation. What you must understand is that when you write Hash.new(Hash.new) is like default_value = Hash.new Hash.new(default_value) i.e. default_value is used each times a key is not defined When you write var['index2']['index22'] = 'value22' because var['index2'] is not defined, ruby will do something like this var['index2'] = default_value default_value['index22'] = 'value22' Same with var['index3']['index32'] = 'value32' it do var['index3'] = default_value default_value['index32'] = 'value32' When you ask for var['donotexist'] it give you the variable default_value, i.e. the hash {"index32" => "value32", "index22" =>"value22"} With 1.7 you'll have the possibility to write Hash.new { Hash.new } and each times a key is not defined, ruby will evaluate the block, the result of the block will be stored in the Hash and ruby will do what you want. Guy Decoux