如何获取调用方法的名称? [英] How to get the name of the calling method?
本文介绍了如何获取调用方法的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Ruby 有没有办法在方法内部找到调用方法名称?
is there a way in Ruby to find the calling method name inside of a method?
例如:
class Test
def self.foo
Fooz.bar
end
end
class Fooz
def self.bar
# get Test.foo or foo
end
end
推荐答案
puts caller[0]
或许……
puts caller[0][/`.*'/][1..-2]
这篇关于如何获取调用方法的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文