# method-names

**URL:** https://rubytalk.org/t/method-names/75554
**Category:** ruby-talk
**Created:** [28 August 2021 23:23 UTC](https://rubytalk.org/t/method-names/75554 "2021-08-28T23:23:53Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Die\_Optimisten](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Die\_Optimisten](https://rubytalk.org/u/Die_Optimisten)
#### Post date: [28 August 2021 23:23 UTC](https://rubytalk.org/t/method-names/75554/1 "2021-08-28T23:23:53Z")

</div>

```
Hello,

```

How do I get the name of the method I'm in (perhaps with line-number) ?  
(like the error-stack when failing)

thank you

Opti

---

<div class="post-metadata">

### Author: ![Gerard\_Fowley](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/gerard_fowley/32/2085_2.png) [@Gerard\_Fowley](https://rubytalk.org/u/Gerard_Fowley)
#### Post date: [28 August 2021 23:48 UTC](https://rubytalk.org/t/method-names/75554/2 "2021-08-28T23:48:08Z")

</div>

> **[Class: Method (Ruby 2.7.0)](https://ruby-doc.org/core-2.7.0/Method.html#method-i-source_location)**
>
> Class : Method - Ruby 2.7.0

> **[Module: Kernel (Ruby 2.7.0)](https://ruby-doc.org/core-2.7.0/Kernel.html#method-i- __method__ )**
>
> Module : Kernel - Ruby 2.7.0

\<[https://ruby-doc.org/core-2.7.0/Kernel.html&gt](https://ruby-doc.org/core-2.7.0/Kernel.html&gt);

\*[1] pry(main)\> def mymethod[1] pry(main)\* [ \_\_method\_\_,  
self.method(\_\_method\_\_).source\_location ][1] pry(main)\* end=\> :mymethod[2]  
pry(main)\> mymethod=\> [:mymethod, ["(pry)", 5]][3] pry(main)\>\*

-gf-

> **···**
>
> On Sat, Aug 28, 2021 at 7:24 PM Die Optimisten \<inform@die-optimisten.net\> wrote:
> 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hello,
> > 
> > How do I get the name of the method I'm in (perhaps with line-number) ?  
> > (like the error-stack when failing)
> > 
> > thank you
> > 
> > Opti
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

### Author: ![Die\_Optimisten](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Die\_Optimisten](https://rubytalk.org/u/Die_Optimisten)
#### Post date: [29 August 2021 15:25 UTC](https://rubytalk.org/t/method-names/75554/3 "2021-08-29T15:25:25Z")

</div>

Hello,

is it possible to do this it only once (metaprogramming), so that it is  
done for all (my) methods starting AND ending ?

- Do I have to build the method-call stack by myself, or can I somehow  
use the avalilable call-stack?

thank you

Opti

> **···**
>
> --
> 
> -gf-

---

<div class="post-metadata">

### Author: ![Xavier\_Noria](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/xavier_noria/32/1867_2.png) [@Xavier\_Noria](https://rubytalk.org/u/Xavier_Noria)
#### Post date: [29 August 2021 15:48 UTC](https://rubytalk.org/t/method-names/75554/4 "2021-08-29T15:48:13Z")

</div>

is it possible to do this

> 

What is "this"?

> **···**
>
> On Sun, Aug 29, 2021 at 5:25 PM Die Optimisten \<inform@die-optimisten.net\> wrote:

---

<div class="post-metadata">

### Author: ![Gerard\_Fowley](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/gerard_fowley/32/2085_2.png) [@Gerard\_Fowley](https://rubytalk.org/u/Gerard_Fowley)
#### Post date: [29 August 2021 18:14 UTC](https://rubytalk.org/t/method-names/75554/5 "2021-08-29T18:14:57Z")

</div>

It sounds like your intention is to trace and log program execution ? ...  
You may find this useful:

> **[Class: TracePoint (Ruby 2.7.0)](https://ruby-doc.org/core-2.7.0/TracePoint.html)**
>
> Class : TracePoint - Ruby 2.7.0

-gf-

> **···**
>
> On Sun, Aug 29, 2021 at 11:25 AM Die Optimisten \<inform@die-optimisten.net\> wrote:
> 
> > Hello,
> > 
> > is it possible to do this it only once (metaprogramming), so that it is  
> > done for all (my) methods starting AND ending ?
> > 
> > - Do I have to build the method-call stack by myself, or can I somehow  
> > use the avalilable call-stack?
> > 
> > thank you
> > 
> > Opti
> > 
> > --
> > 
> > -gf-
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);

---

<div class="post-metadata">

### Author: ![hmdne](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@hmdne](https://rubytalk.org/u/hmdne)
#### Post date: [30 August 2021 13:27 UTC](https://rubytalk.org/t/method-names/75554/6 "2021-08-30T13:27:56Z")

</div>

You most probably think about one of these methods:

[https://rubyapi.org/3.0/o/kernel#method-i-caller](https://rubyapi.org/3.0/o/kernel#method-i-caller)

[https://rubyapi.org/3.0/o/kernel#method-i-caller\_locations](https://rubyapi.org/3.0/o/kernel#method-i-caller_locations)

The first one returns Strings, the second one a Thread::Backtrace::Location which respond to methods like #lineno and #label which can help you achieve what I think you try to achieve.

> **···**
>
> On 8/29/21 1:23 AM, Die Optimisten wrote:
> 
> > Hello,
> > 
> > How do I get the name of the method I'm in (perhaps with line-number) ?  
> > (like the error-stack when failing)
> > 
> > thank you
> > 
> > Opti
> > 
> > Unsubscribe: \<mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe\>  
> > \<[http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt](http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt);
