On Fri, Apr 15, 2011 at 2:50 PM, I=F1aki Baz Castillo <ibc / aliax.net> wrote=
:
> However I've realized right now that it's not possible. The hash key
> doesn't store the given key as a reference to such object:

This is a special optimization for unfrozen Strings as Hash keys.

> Now I have another question:
>
> --------------------
> myobject =3D MyCustomClass.new
>
> @h =3D {}
>
> @h[myobject] =3D "lalalala"
> --------------------
>
> In this case, will Ruby GC delete myobject? or will it remain alive as
> it has been used as a key of a hash (which is not GC'd in a supposed
> code)?

The key stays alive at least as long as the Hash instance.

Cheers

robert


--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/