获取称为当前方法的方法

atm*_*ell 2 ruby

可能重复:
如何获取调用方法的名称?

在下面的示例中,如何告诉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)

izo*_*ica 5

例如:puts caller[0]这将为您提供呼叫者的信息.