0

Say I have a function:

def foo() puts getFunctionIAMIn() end 

I want the output to be:"foo" And if I have this code:

def foo1() puts getFunctionIAMIn() end 

I want the output to be:"foo1"

1
  • The question, in a different phrasing, how do I realize getFunctionIAMIn() ? Commented Mar 6, 2014 at 13:26

2 Answers 2

5

Just write as below using __method__:

def foo() puts __method__ end 

Above is correct, but __callee__ sounds more technically correct.

__method__ returns defined name, and __callee__ returns called name.They are same usually, but different in a aliased method.

def foo [__method__, __callee__] end alias bar foo p foo #=> [:foo, :foo] p bar #=> [:foo, :bar] 
Sign up to request clarification or add additional context in comments.

7 Comments

You beat me by 8 seconds :D
Do you know how it is different from __callee__?
@Stefan No they are not... :)
@sawa Got your point.. __callee__ is more technically correct.. Let me edit.
|
2

You can use __method__ for that:

def test_method __method__ end 

1 Comment

Do you thin your answer and my one is different ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.