On Sun, 24 Dec 2000, ts wrote:

> >>>>> "B" == Ben Tilly <ben_tilly / hotmail.com> writes:
> 
> B>   puts h[a]
> 
>      puts h[a.to_s]

And yet...

   class Foo < String
     def to_s
       "to_s method"
     end
   end
   
   a = Foo.new("Hello");
   puts a.to_s
   
   h = {'Hello' => 'World'}
   puts h[a]
                      
     => to_s method
        World           

Also:

   b = Foo.new("Hi")
   h[b] = 123
   h.each_key do |k| puts k.type end 
     => String
        String

so somehow the Foo objects get stringified, when used as
hash keys in setting or fetching.  In that sense, I do see
what Ben means: you can't (it appears) have a hash key that
starts out as a Foo object and remains a Foo object.

If you use a string variable, it also gets "stringified",
in the sense that the key is not the same object as the
variable

   s = "thing"
   h[s] = 123

   s.id and the id of the "thing" key of h are different.

and Foo apparently inherits that behavior.  It almost has the
flavor of:

   h["#{b}"] = 123

But I can't figure out exactly where it happens.  I tried
overriding to_str, dup, and clone -- couldn't break it.


David 

-- 
writing from alternate site/address 
real email address == dblack / candle.superlink.net
but this one will work in a pinch