How to return string name of calling method?
Posted
by keruilin
on Stack Overflow
See other posts from Stack Overflow
or by keruilin
Published on 2010-04-07T18:39:16Z
Indexed on
2010/04/07
18:43 UTC
Read the original article
Hit count: 203
Right now my code works as such:
def method_a
self.method_b ==> 'method_b'
end
def method_b
puts self.name_of_calling_method
end
def name_of_calling_method
if /`(.*)'/.match(caller.first)
return $1
else
return nil
end
end
Instead of method_b printing 'method_b', how can I print the name of the calling method - 'method_a'?
© Stack Overflow or respective owner