From: Robert Klemme Date: 2006-03-30T17:18:43+09:00 Subject: Re: accessing the currently running method Kev Jackson wrote: > is caller the best way to access the name of the current method? > > ie if I have a method called x, is there any other way to determine at > runtime the exact method that is executing? caller would return an > array (limited by the int param) of the call stack, but I'd still have > to search across the array (with a regexp) to extract the method name > > with caller I can do something like... > > ms = ["prog:1:in `x'"] > > ms.each { |m| /x/=~m do_stuff } > > Is there no other way? no Kernel.running_method, no Kernel.executing? > Are there any libraries that would give me this level of inspection > without extending Kernel? (I'm thinking of evil.rb here) There is binding_of_caller which might or might not help you - depending on what you want to do. Another option is to use set_trace_func to set up something that keeps track of method invocations. > No biggy, just interested if anyone else has ever wanted/needed to get > this info in a running program, and what they did to do it Certainly, from time to time. What do *you* need it for? Kind regards robert