【发布时间】:2013-01-21 16:23:32
【问题描述】:
在下面的例子中,我如何知道什么方法叫做 foo?
class Example
def initialize
end
def foo
puts "Hello World"
end
def bar
foo
end
def cats
bar
end
end
Example.new.cats 打印条。我正在尝试获取整个调用堆栈。例如。猫 -> 酒吧 -> foo
更新:
这行得通: puts caller[0..1]
Hello World
(irb):11:in `bar'
(irb):15:in `cats'
【问题讨论】:
-
应该在运行时决定。
标签: ruby