From: Ilias Lazaridis Date: 2011-05-27T04:55:33+09:00 Subject: Re: CORE - Object Instantiation and Location On 26 Μάϊος, 13:31, Roger Braun wrote: > 2011/5/26 Ilias Lazaridis : > > > > > What I'm looking for: > > > how can I detect WHERE the object was instantiated? > > This seems to do what you need. > > http://snippets.dzone.com/posts/show/2787 Yes, this seems to do it for file/line/method > See also here: > > http://www.ruby-doc.org/core/classes/Kernel.html#M001397 That seems to contain the solution for the function name. And this is the right documentation, but I could not find (within Object and Kernel) the construct I'm looking for (accessing calling Module or Object). #ruby 1.9 class Person def initialize(name) @name = name @where = self.invoked_from # returns Object end def report print "\n", @name, " instantiated in: ", @where, "\n" end end p = Person.new("Nancy") p.report #=> Nancy instantiated in: main Is there something like "self.invocation_from", or how could this be implemented? Note that this should work on object model, returning a "living" object. . -- http://lazaridis.com