From: Trans Date: 2007-07-17T01:13:51+09:00 Subject: Re: Accessing the name of the current function On Jul 16, 10:56 am, "Ronald Fischer" wrote: > Is there away to access the name of the currently defined function? > Example: Right now I do tracing like this: > > def myfunc(a,b) > trace.debug "ENTER myfunc a=#{a} b=#{b}" > .... > trace.debug "LEAVE myfunc result=#{result}" > result > end > > If I rename myfunc, I also have to change the word myfunc in the > trace statements. It would be convenient to have something like > > trace.debug "ENTER #{__function__} a=#{a} b=#{b}" Facets has this Kernel method for it. module Kernel def called /\`([^\']+)\'/.match(caller(1).first)[1].to_sym end end See http://facets.rubyforge.org. I think the plan for 1.9 is to have __method__ and __callee__, which differ based on aliasing. (Guess Matz decided __shadow__ methods are here to stay). T.