Get the function name from it's body in Ruby -


this question has answer here:

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

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -