From: David Maciejak Date: 2009-06-09T18:52:12+09:00 Subject: ruby dup unexpected behaviour Hi, I got no answer on ubuntu entry at https://bugs.launchpad.net/ubuntu/+source/ruby1.8/+bug/384265 so I resend it here. Does someone have any clues on this ? Thanks, david -------------------------------------------------------------------------------------- Hi, got some strange result in ruby1.8 (1.8.7.72-3) on jaunty (up to date). Don't know if I use correctly dup function but my duped hash is modified even if i call the freeze method. Below the quick and dirty test case showing that @c member of the class Global is modified #!/usr/bin/ruby class Testme attr_accessor :value def initialize(val) @value=val end def Testme::bou(val) $a["b"].value=val end def to_str() print @value,"\n" end end class Global def initialize @c=nil end def go() @c=$a.dup @c.freeze #print value before the changes to_str() end def to_str() print @c,"\n" end end $a=Hash.new $a["a"]=Testme.new(1) $a["b"]=Testme.new(2) main=Global.new main.go() Testme::bou(3) #print value after the changes main.to_str()