Well I know that objects are supposed to be usable as the
keys of hashes.  And indeed in a simple test it works as
I would expect from that description:

  h = {12 => "Hello", "12" => "World"}
  puts h[12]
  puts h["12"]

But in a more complex test:

  class Foo < String
    def foo= (foo)
      @foo = foo
    end
    def foo
      @foo
    end
  end

  a = Foo.new("Hello");
  a.foo = "Something"
  h = {'Hello' => 'World'}
  puts h[a]
  puts a.foo

Well the object a certainly is not the same object as the
string 'Hello' - it is in a different class and has a
property of its own.  (Not to mention that they are
different instances.)  But in a hash it was somehow
identified with that string.  There seems to be some sort
of mapping from specific instance to canonical object.

So how does this work?  How does Ruby determine the thing
hash?  (In Perl it is really simple, everything is
converted to a string and then the strings are hashed.)

Thanks,
Ben
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com