From: Robert Feldt Date: 2001-02-20T01:55:08+09:00 Subject: [ruby-talk:11118] Re: Auto-magically determine your class/method in Ruby On Tue, 20 Feb 2001, Bryan Zarnett wrote: > Is their a way to auto-magically determine the class > and method that called an operation in another class. > For example, I have a logger class that would like to > embed in the output line the Class and operation that > logged a message. I don't want to have to pass this > information as an argument if I have to. > There are probably much easier and nicer ways (using Kernel#caller?) but I've contemplated doing something like (*VERY* ugly): * Set a trace_func in callee: trace_func should catch "return" event and save id (method) and classname (class) for access from callee * (Rest of callee code in proc or method accessible from trace_func) * Return from callee * (trace func now invoked, extracts info and calls rest of callee code) End of trace_func unset this trace_func * "Real" return to caller We'll probably all laugh at this solution when one of the Ruby gurus comes along with the right way to do it... :-) /R