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

python - matpltolib navigation toolbar edit curves and parameters line color automatically changes issue -

node.js - Nodejs javascript implementation of PBEWithMD5AndTripleDES/CBC/PKCS5Padding -