# How to get the method name

**URL:** <https://www.ruby-forum.com/t/how-to-get-the-method-name/126005>\
**Category:** Ruby\
**Created:** [January 14, 2008, 5:14pm UTC](https://www.ruby-forum.com/t/how-to-get-the-method-name/126005 "2008-01-14T17:14:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [January 14, 2008, 5:14pm UTC](https://www.ruby-forum.com/t/how-to-get-the-method-name/126005/1 "2008-01-14T17:14:23Z")

</div>

I need to get the method name automatically like we do with the classes:

puts self.class.to\_s()

I’m trying: self.method.to\_s() or self.class.method.to\_s() but it  
doesn’t work.

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [January 14, 2008, 5:32pm UTC](https://www.ruby-forum.com/t/how-to-get-the-method-name/126005/2 "2008-01-14T17:32:50Z")

</div>

I don’t think I’ve got your question exactly, but  
self.methods returns an array of all methods defined in self.  
If not exactly what you want, probably  
one of the Object class methods for self inspection is what you are  
looking for.  
-Carlos

On Tue, 15 Jan 2008 01:14:18 +0900, “Mario R.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
said:

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [January 14, 2008, 5:39pm UTC](https://www.ruby-forum.com/t/how-to-get-the-method-name/126005/3 "2008-01-14T17:39:57Z")

</div>

Hi Mario,

have a look at this thread:

[http://www.ruby-forum.com/topic/75258](http://www.ruby-forum.com/topic/75258)

For pre ruby 1.9 you’ll have to use a work-around.

cheers

Thibaut

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [January 15, 2008, 11:19am UTC](https://www.ruby-forum.com/t/how-to-get-the-method-name/126005/4 "2008-01-15T11:19:40Z")

</div>

Thank you very much.

Thibaut BarrÃ¨re wrote:

> Hi Mario,
> 
> have a look at this thread:
> 
> [Using the current method name within current method - Ruby - Ruby-Forum](http://www.ruby-forum.com/topic/75258)
> 
> For pre ruby 1.9 you’ll have to use a work-around.
> 
> cheers
> 
> Thibaut
