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

**URL:** <https://www.ruby-forum.com/t/is-there-a-method-to-tell-me-the-name-of-the-method-im-in/169997>\
**Category:** Ruby\
**Created:** [June 11, 2009, 3:38am UTC](https://www.ruby-forum.com/t/is-there-a-method-to-tell-me-the-name-of-the-method-im-in/169997 "2009-06-11T03:38:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xeno\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/958977/32.png) [@Xeno\_C](https://www.ruby-forum.com/u/Xeno_C)\
**Post date:** [June 11, 2009, 3:38am UTC](https://www.ruby-forum.com/t/is-there-a-method-to-tell-me-the-name-of-the-method-im-in/169997/1 "2009-06-11T03:38:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Xeno\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/958977/32.png) [@Xeno\_C](https://www.ruby-forum.com/u/Xeno_C)\
**Post date:** [June 11, 2009, 4:31am UTC](https://www.ruby-forum.com/t/is-there-a-method-to-tell-me-the-name-of-the-method-im-in/169997/2 "2009-06-11T04:31:10Z")

</div>

Xeno C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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! 🙂 m.

---

<div class="post-metadata">

**Author:** ![Xeno\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/958977/32.png) [@Xeno\_C](https://www.ruby-forum.com/u/Xeno_C)\
**Post date:** [June 11, 2009, 4:46am UTC](https://www.ruby-forum.com/t/is-there-a-method-to-tell-me-the-name-of-the-method-im-in/169997/3 "2009-06-11T04:46:57Z")

</div>

On Thu, Jun 11, 2009 at 9:37 AM, Xeno  
Campanoli[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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’”

---

<div class="post-metadata">

**Author:** ![Xeno\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/958977/32.png) [@Xeno\_C](https://www.ruby-forum.com/u/Xeno_C)\
**Post date:** [June 11, 2009, 5:43am UTC](https://www.ruby-forum.com/t/is-there-a-method-to-tell-me-the-name-of-the-method-im-in/169997/4 "2009-06-11T05:43:40Z")

</div>

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.
