0

我需要找到哪个方法叫做“abc”,在此基础上我可以做一些操作。

Class A
  def method1
   abc
  end

  def method2
   abc
  end

  def abc
   puts "abc" if calling_method == :method1
   puts "xyz" 
  end
end

这在红宝石中可能吗?

4

1 回答 1

4

您可以使用该caller()方法。

http://www.ruby-doc.org/core-2.0/Kernel.html#method-i-caller

于 2013-03-02T12:12:38.740 回答