From: Dmitry Perfilyev Date: 2008-12-11T16:34:58+09:00 Subject: Re: why Hash corrupts 'key' object ? Mike Gold wrote: > It must be the T_STRING test in hash.c, an optimization, I assume. > > VALUE > rb_hash_aset(hash, key, val) > VALUE hash, key, val; > { > rb_hash_modify(hash); > if (TYPE(key) != T_STRING || st_lookup(RHASH(hash)->tbl, key, 0)) { > st_insert(RHASH(hash)->tbl, key, val); > } > else { > st_add_direct(RHASH(hash)->tbl, rb_str_new4(key), val); > } > return val; > } > > You can still use your code as is, with this adjustment: > > require 'delegate' > > class TestStr < DelegateClass(String) > # ... > end > > Also consider delegation as a primary strategy, not just as a workaround > for this case. Thanks! It works (although I had to implement hash() and eql?() methods for TestStr) BTW, why delegation is more primary than standard inheritance ? -- Posted via http://www.ruby-forum.com/.