From: Brian Adkins Date: 2008-12-14T03:32:53+09:00 Subject: Re: why Hash corrupts 'key' object ? Mike Gold writes: > Brian Adkins wrote: >> Mike Gold writes: >> >>> rb_str_new4(orig) >>> >>> The docs could be made clearer: An _unfrozen_ String passed as a key >>> will be duplicated and frozen. >> >> That doesn't answer my question. I showed that dup+freeze did not >> adversely affect TestStr (i.e. dupstr was still accessible), so >> something else is going on. > > You passed in a frozen String, so Hash#[]= did not touch it. So it was > not adversely affected. No I didn't. In fact, I didn't even use Hash in the example. Maybe you're referring to a different post. I'll repost below: $ cat -n temp.rb 1 class TestStr < String 2 attr_accessor :dupstr 3 def initialize ( str ) 4 @dupstr = str 5 super(str) 6 end 7 end 8 ts=TestStr.new("aaa") 9 puts ts.dupstr, ts.object_id 10 puts '---' 11 ts2 = ts.dup 12 ts2.freeze 13 puts ts2.dupstr, ts2.object_id $ ruby temp.rb aaa 81910 --- aaa 81880 What the above demonstrates is that dup'ing and freezing a TestStr does not nilify TestStr#dupstr, so the C code for Hash seems to be doing more than just dup'ing and freezing. Does that make sense? > > Could you write an assertion which you think should succeed but doesn't? > -- > Posted via http://www.ruby-forum.com/. > -- Brian Adkins http://www.lojic.com/ http://lojic.com/blog/