From: Matthias Georgi Date: 2004-05-14T06:50:49+09:00 Subject: [RCR] subclasses of string as hash keys Current behaviour in Ruby is irritating. example: class A < String; end hash = {} hash[ A.new('x') ] = nil p hash.keys.first.class => String Strings get copied, when they get inserted as keys, this is intended, I think. But if I choose to insert a subclassed object, I expect to get the same class back, copied or not. So I suggest, to change in rb_hash_aset: - if (TYPE(key) != T_STRING || st_lookup(RHASH(hash)->tbl, key, 0)) { - st_insert(RHASH(hash)->tbl, key, val); - } + if ( RBASIC(key)->klass != rb_cString || st_lookup(RHASH(hash)->tbl, key, 0)) { + st_insert(RHASH(hash)->tbl, key, val); + } This was discussed long time ago in [ruby-talk:8050]. -- Matthias Georgi matti_g@gmx.de