From: Robert Klemme Date: 2011-04-15T22:00:05+09:00 Subject: Re: Get the real object in a Hash key On Fri, Apr 15, 2011 at 2:50 PM, Iņaki Baz Castillo 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 = MyCustomClass.new > > @h = {} > > @h[myobject] = "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 -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/