# Is there a method I can call where:

**URL:** https://rubytalk.org/t/is-there-a-method-i-can-call-where/58931
**Category:** ruby-talk
**Created:** [18 June 2010 20:03 UTC](https://rubytalk.org/t/is-there-a-method-i-can-call-where/58931 "2010-06-18T20:03:35Z")
**Posts on this page:** 5
**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: [18 June 2010 20:03 UTC](https://rubytalk.org/t/is-there-a-method-i-can-call-where/58931/1 "2010-06-18T20:03:35Z")

</div>

If I have:

class Blek  
&nbsp;&nbsp;&nbsp;&nbsp;def bM  
&nbsp;&nbsp;puts "trace #{self.somemethod}"  
&nbsp;&nbsp;&nbsp;&nbsp;end  
end

bo = Blek.new  
[bo.bM](http://bo.bM)

It will give me:

trace [bo.bM](http://bo.bM)  
or  
trace bM

???

I want to set up stuff that tells me what method I am in, largely for raising exceptions in various circumstances, but I want to control the message myself, so I'd like specifically knowledge of the method name available as stated.

> **···**
>
> --  
> "It's the preponderance, stupid!" - Professor Stephen Schneider, IPCC member

---

<div class="post-metadata">

### Author: ![Marvin\_GA\_lker](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@Marvin\_GA\_lker](https://rubytalk.org/u/Marvin_GA_lker)
#### Post date: [18 June 2010 20:32 UTC](https://rubytalk.org/t/is-there-a-method-i-can-call-where/58931/2 "2010-06-18T20:32:28Z")

</div>

Xeno Campanoli / Eskimo North and Gmail wrote:

> so I'd like specifically knowledge of the method name available as  
> stated.

The \_\_method\_\_ method should do the trick:

ruby -v: ruby 1.9.1p378 (2010-01-10 revision 26273) [x86\_64-linux]  
irb(main):001:0\> def foo  
irb(main):002:1\> p \_\_method\_\_  
irb(main):003:1\> end  
=\> nil  
irb(main):004:0\> foo  
:foo  
=\> :foo  
irb(main):005:0\>

That one is implemented since 1.8.7 I think. The class name is available  
via #class.

Marvin

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

---

<div class="post-metadata">

### Author: ![7rans](https://avatars.discourse-cdn.com/v4/letter/7/a8b319/32.png) [@7rans](https://rubytalk.org/u/7rans)
#### Post date: [18 June 2010 20:32 UTC](https://rubytalk.org/t/is-there-a-method-i-can-call-where/58931/3 "2010-06-18T20:32:32Z")

</div>

\_\_method\_\_ or \_\_callee\_\_

> **···**
>
> On Jun 18, 4:03 pm, Xeno Campanoli / Eskimo North and Gmail \<xeno.campan...@gmail.com\> wrote:
> 
> > If I have:
> > 
> > class Blek  
> > def bM  
> > puts "trace #{self.somemethod}"  
> > end  
> > end
> > 
> > bo = Blek.new  
> > bo.bM
> > 
> > It will give me:
> > 
> > trace bo.bM  
> > or  
> > trace bM
> > 
> > ???
> > 
> > I want to set up stuff that tells me what method I am in, largely for raising  
> > exceptions in various circumstances, but I want to control the message myself,  
> > so I'd like specifically knowledge of the method name available as stated.  
> > --  
> > "It's the preponderance, stupid!" - Professor Stephen Schneider, IPCC member

---

<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: [18 June 2010 20:44 UTC](https://rubytalk.org/t/is-there-a-method-i-can-call-where/58931/4 "2010-06-18T20:44:49Z")

</div>

> \_\_method\_\_ or \_\_callee\_\_

Thank you. \_\_method\_\_ seems to work, but \_\_callee\_\_ seems to fail, and I cannot find it in pickaxe:

> ./test.rb:8:in `bm': undefined local variable or method `\_\_callee\_\_' for #\<Blek:0xb78989f8\> (NameError)  
> &nbsp;&nbsp;from ./test.rb:18

I tried several variations of that too, and they all fail. Still, you got me going. Thank you very much.

Sincerely, Xeno.  
xc

> **···**
>
> On 10-06-18 01:32 PM, Intransition wrote:
> 
> > On Jun 18, 4:03 pm, Xeno Campanoli / Eskimo North and Gmail \> \<xeno.campan...@gmail.com\> wrote:
> > 
> > > If I have:
> > > 
> > > class Blek  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def bM  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "trace #{self.somemethod}"  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> > > end
> > > 
> > > bo = Blek.new  
> > > bo.bM
> > > 
> > > It will give me:
> > > 
> > > trace bo.bM  
> > > or  
> > > trace bM
> > > 
> > > ???
> > > 
> > > I want to set up stuff that tells me what method I am in, largely for raising  
> > > exceptions in various circumstances, but I want to control the message myself,  
> > > so I'd like specifically knowledge of the method name available as stated.  
> > > --  
> > > "It's the preponderance, stupid!" - Professor Stephen Schneider, IPCC member
> 
> --  
> "It's the preponderance, stupid!" - Professor Stephen Schneider, IPCC member

---

<div class="post-metadata">

### Author: ![7rans](https://avatars.discourse-cdn.com/v4/letter/7/a8b319/32.png) [@7rans](https://rubytalk.org/u/7rans)
#### Post date: [18 June 2010 22:21 UTC](https://rubytalk.org/t/is-there-a-method-i-can-call-where/58931/5 "2010-06-18T22:21:58Z")

</div>

It's a 1.9. thing:

&nbsp;&nbsp;[http://eigenclass.org/hiki/Changes+in+Ruby+1.9#l168](http://eigenclass.org/hiki/Changes+in+Ruby+1.9#l168)

> **···**
>
> On Jun 18, 4:44 pm, Xeno Campanoli / Eskimo North and Gmail \<xeno.campan...@gmail.com\> wrote:
> 
> > On 10-06-18 01:32 PM, Intransition wrote:
> > 
> > \> \_\_method\_\_ or \_\_callee\_\_
> > 
> > Thank you. \_\_method\_\_ seems to work, but \_\_callee\_\_ seems to fail, and I cannot  
> > find it in pickaxe:
> > 
> > \> ./test.rb:8:in `bm': undefined local variable or method `\_\_callee\_\_' for #\<Blek:0xb78989f8\> (NameError)  
> > \> from ./test.rb:18
