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

**URL:** https://rubytalk.org/t/is-there-a-method-to-tell-me-the-name-of-the-method-im-in/53850
**Category:** ruby-talk
**Created:** [11 June 2009 01:37 UTC](https://rubytalk.org/t/is-there-a-method-to-tell-me-the-name-of-the-method-im-in/53850 "2009-06-11T01:37:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Xeno\_Campanoli1](https://avatars.discourse-cdn.com/v4/letter/x/85f322/32.png) [@Xeno\_Campanoli1](https://rubytalk.org/u/Xeno_Campanoli1)
#### Post date: [11 June 2009 01:37 UTC](https://rubytalk.org/t/is-there-a-method-to-tell-me-the-name-of-the-method-im-in/53850/1 "2009-06-11T01:37:41Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Matt\_Neuburg](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@Matt\_Neuburg](https://rubytalk.org/u/Matt_Neuburg)
#### Post date: [11 June 2009 02:30 UTC](https://rubytalk.org/t/is-there-a-method-to-tell-me-the-name-of-the-method-im-in/53850/2 "2009-06-11T02:30:11Z")

</div>

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

def other\_method  
&nbsp;&nbsp;raise  
end  
def what\_method  
&nbsp;&nbsp;other\_method  
end  
begin  
&nbsp;&nbsp;what\_method  
rescue  
&nbsp;&nbsp;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.

> **···**
>
> Xeno Campanoli \<xeno.campanoli@gmail.com\> wrote:
> 
> > This would be handy with some of my class methods for composing exception  
> > messages...??

---

<div class="post-metadata">

### Author: ![botp1](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@botp1](https://rubytalk.org/u/botp1)
#### Post date: [11 June 2009 02:46 UTC](https://rubytalk.org/t/is-there-a-method-to-tell-me-the-name-of-the-method-im-in/53850/3 "2009-06-11T02:46:24Z")

</div>

> 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  
> &nbsp;&nbsp;caller[0]  
> end

=\> nil

> def m  
> &nbsp;&nbsp;whoami  
> end

=\> nil

> m

=\> "(irb):62:in `m'"

> **···**
>
> On Thu, Jun 11, 2009 at 9:37 AM, Xeno Campanoli\<xeno.campanoli@gmail.com\> wrote:
> 
> >

---

<div class="post-metadata">

### Author: ![Gary\_Wright](https://avatars.discourse-cdn.com/v4/letter/g/58956e/32.png) [@Gary\_Wright](https://rubytalk.org/u/Gary_Wright)
#### Post date: [11 June 2009 03:42 UTC](https://rubytalk.org/t/is-there-a-method-to-tell-me-the-name-of-the-method-im-in/53850/4 "2009-06-11T03:42:57Z")

</div>

It Ruby 1.9, \_\_callee\_\_ (or \_\_method\_\_) will return the name of the current method as a symbol.

Gary Wright

> **···**
>
> On Jun 10, 2009, at 9:37 PM, Xeno Campanoli wrote:
> 
> > This would be handy with some of my class methods for composing exception messages...??
