From: OliverMarchand Date: 2005-10-12T23:06:53+09:00 Subject: Hash as a class variable Hi ruby fans, I am a python2ruby switcher and just encountered this problem today with a class variable: --- class Testclass @@myhash = Hash.new({"a"=>"aaaah"}) def initialize() p @@myhash end end T = Testclass.new --- yields {} whixh surprises me, becasue I would expect myhash to have an entry and not be the empty hash. The only way I found to fix this was: --- class Testclass @@myhash = nil def initialize() @@myhash = Hash.new() @@myhash["a"] = "aaaah" p @@myhash end end T = Testclass.new --- which yields what I expect: {"a"=>"aaaah"} I have searched in the FAQ's, Things to know about ruby, websites, etc. but just couldn't find any hint. Examples are never hashes. ciao, Oliver