Rubyで今実行中のメソッド名を知る
Rubyで今実行中のメソッド名を知る - 2nd life
callerを使うと例外を投げなくてもバックトレースの情報を取得できます。これを使うともう少し簡単になりそうです。こんな感じでしょうか。
#!/usr/bin/env ruby class Object def current_method caller.first.scan(/`(.*)'/).to_s end end def foo p current_method end def bar foo p current_method end bar # => "foo" # "bar" p current_method # => ""
参照: プログラミング言語 Ruby リファレンスマニュアル
実は僕もid:ha-tan:20050816:1124154888でなかださんに教えてもらいました。