# How to get the method name

**URL:** https://rubytalk.org/t/how-to-get-the-method-name/43756
**Category:** ruby-talk
**Created:** [14 January 2008 16:14 UTC](https://rubytalk.org/t/how-to-get-the-method-name/43756 "2008-01-14T16:14:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Mario\_Ruiz](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@Mario\_Ruiz](https://rubytalk.org/u/Mario_Ruiz)
#### Post date: [14 January 2008 16:14 UTC](https://rubytalk.org/t/how-to-get-the-method-name/43756/1 "2008-01-14T16:14:18Z")

</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.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

### Author: ![Carlos\_Hernandez](https://avatars.discourse-cdn.com/v4/letter/c/5f8ce5/32.png) [@Carlos\_Hernandez](https://rubytalk.org/u/Carlos_Hernandez)
#### Post date: [14 January 2008 16:30 UTC](https://rubytalk.org/t/how-to-get-the-method-name/43756/2 "2008-01-14T16:30:22Z")

</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 Ruiz" \<mario@betware.com\> said:
> 
> > 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.  
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![thbar](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/thbar/32/1892_2.png) [@thbar](https://rubytalk.org/u/thbar)
#### Post date: [14 January 2008 16:35 UTC](https://rubytalk.org/t/how-to-get-the-method-name/43756/3 "2008-01-14T16:35:06Z")

</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

> **···**
>
> --  
> [http://blog.logeek.fr](http://blog.logeek.fr) - about writing software  
> [http://evolvingworker.com](http://evolvingworker.com) - tools for a better day

---

<div class="post-metadata">

### Author: ![Mario\_Ruiz](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@Mario\_Ruiz](https://rubytalk.org/u/Mario_Ruiz)
#### Post date: [15 January 2008 10:19 UTC](https://rubytalk.org/t/how-to-get-the-method-name/43756/4 "2008-01-15T10:19:37Z")

</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
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
