Get the function name from it's body in Ruby -
this question has answer here:
- get name of executing method 5 answers
say have function:
def foo() puts getfunctioniamin() end
i want output be:"foo" , if have code:
def foo1() puts getfunctioniamin() end
i want output be:"foo1"
just write below using __method__
:
def foo() puts __method__ end
above correct, __callee__
sounds more technically correct.
__method__
returns defined name, , __callee__
returns called name.they same usually, different in aliased method.
def foo [__method__, __callee__] end alias bar foo p foo #=> [:foo, :foo] p bar #=> [:foo, :bar]
Comments
Post a Comment