可能重复:
如何获取调用方法的名称?
在下面的示例中,如何告诉foo使用哪种方法?
class Example
def initialize
end
def foo
puts "Hello World"
end
def bar
foo
end
def cats
bar
end
end
Run Code Online (Sandbox Code Playgroud)
Example.new.cats打印栏.我想要获得整个callstack.例如猫 - >吧 - > foo
更新:
这有效:把来电者[0..1]
Hello World
(irb):11:in `bar'
(irb):15:in `cats'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
192 次 |
| 最近记录: |