Markus Fischer wrote:
> I figured out the following:
> 
> - Set uses Hash internall
> - Hash.store says the following about Strings:
> "a String passed as a key will be duplicated and frozen"

Ah yes, that's right. It's a general problem with Hash that if you 
mutate an object, it will still be sitting on the old (wrong) hash 
chain, and so won't be found by value.

Strings are very common as hash keys, so Ruby decided to special-case 
this to minimise foot-shooting. However the problem still remains for 
other mutable objects:

irb(main):001:0> a = [1,2,3]
=> [1, 2, 3]
irb(main):002:0> h = {a => 99}
=> {[1, 2, 3]=>99}
irb(main):003:0> h[[1,2,3]]
=> 99
irb(main):004:0> a.push(4)
=> [1, 2, 3, 4]
irb(main):005:0> h.keys
=> [[1, 2, 3, 4]]
irb(main):006:0> h[[1,2,3,4]]
=> nil
irb(main):007:0> h.rehash
=> {[1, 2, 3, 4]=>99}
irb(main):008:0> h[[1,2,3,4]]
=> 99

And you're also right that if you 'dup' an object which has singleton 
methods, those are lost in the copy (otherwise, it wouldn't be a 
singleton any more :-)

Regards,

Brian.
-- 
Posted via http://www.ruby-forum.com/.