重複の可能性:
呼び出し元のメソッドの名前を取得する方法は?
次の例で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
アップデート:
これは機能します:caller[0..1]を置きます
Hello World
(irb):11:in `bar'
(irb):15:in `cats'