Is there a method to tell me the name of the method I'm in?

This would be handy with some of my class methods for composing
exception
messages…??

Xeno C. [email protected] wrote:

This would be handy with some of my class methods for composing exception
messages…??

I think the standard thing to do is to munge Exception’s backtrace:

def other_method
raise
end
def what_method
other_method
end
begin
what_method
rescue
puts $!.backtrace[0].split(" ")[1][1…-2]
end

At least that is the sort of thing I have been resorting to; if there is
a better way I’d like to know about it! :slight_smile: m.

On Thu, Jun 11, 2009 at 9:37 AM, Xeno
Campanoli[email protected] wrote:

This would be handy with some of my class methods for composing exception
messages…??

maybe you can call caller and it will tell you who you are
eg,

def whoami
caller[0]
end
=> nil

def m
whoami
end
=> nil

m
=> “(irb):62:in `m’”

On Jun 10, 2009, at 9:37 PM, Xeno C. wrote:

This would be handy with some of my class methods for composing
exception messages…??

It Ruby 1.9, callee (or method) will return the name of the
current method as a symbol.

Gary W.