From: Robert Klemme Date: 2011-05-31T00:00:12+09:00 Subject: Re: CORE - Object Instantiation and Location On Mon, May 30, 2011 at 11:05 AM, Ilias Lazaridis wrote: > On 30 Μάϊος, 11:06, Jesús Gabriel y Galán > wrote: >> On Mon, May 30, 2011 at 9:55 AM, Ilias Lazaridis wrote: > [...] > >> > for "class:MyClass' >> >> > obj = Kernel.const_get("MyClass") #=> returns object which represents >> > MyClass >> >> > for "main"? >> >> > How can I retrieve the "main" object? > [...] >>     eval 'self', TOPLEVEL_BINDING > [...] > > Very nice, this works fine! The approach is broken because you will never properly track anonymous objects. E.g. class Bar; end class Factory def create Bar.new end end bar = Factory.new.create # now our creator is gone If you want to make this traceable you will keep significantly more objects alive than without creation tracking. I suggest you settle with file and line number which should be sufficient in the general case to identify the source location. With a bit of coding you can even make this very memory savvy so the overhead is far less than if you keep hold on the creator instance. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/