From: Jonas Delfs Date: 2002-03-27T23:49:09+09:00 Subject: Re: Hash.new(Hash.new) doesn't use Hash.new as default value "ts" skrev i en meddelelse news:200203271416.g2REGPk06934@moulon.inra.fr... > >>>>> "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) Ohh. I think it's the fact that everything by default gets passed by reference that have tricked me. I can't force Ruby to .dup that object, can I? > 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. Okay. -- Mvh./Best Regards Jonas Delfs, http://delfs.dk