"David A. Black" <dblack / saturn.superlink.net> writes: > Also: > > b = Foo.new("Hi") > h[b] = 123 > h.each_key do |k| puts k.type end > => String > String Even worse class Foo < String def hash super + 1 end end f = Foo.new("hello") h = { f => "one", "hello" => "two" } p h #=> "hello" => two I emailed Matz on this last night: I suspect we have a bug where subclasses of String get treated as if they were strings. When a string is used as a hash key, it is copied automatically, so that subsequent changes to the string don't affect the hash. I'm guessing that the Foo object is undergoing the same treatment, and therefore that Ruby can't tell the resulting copied key from the next "hello" that comes along. > If you use a string variable, it also gets "stringified", > in the sense that the key is not the same object as the > variable That's the copying I talked about. Dave