From: Brian Adkins Date: 2008-12-13T03:13:04+09:00 Subject: Re: why Hash corrupts 'key' object ? Mike Gold writes: > Brian Adkins wrote: >> >> Why would that cause this effect though? The docs say "a String passed >> as a key will be duplicated and frozen", but duplicating and freezing >> a TestStr doesn't nullify dupstr: > > The answer lies in the rb_hash_aset() function I quoted. rb_str_new4() > begins like this: > > VALUE > rb_str_new4(orig) > VALUE orig; > { > VALUE klass, str; > > if (OBJ_FROZEN(orig)) return orig; > /* ... */ > } > > Like Robert showed, if it's already frozen then the key is untouched (no > dup+freeze). > > 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. > -- > Posted via http://www.ruby-forum.com/. > -- Brian Adkins http://www.lojic.com/ http://lojic.com/blog/