$0
is the variable for the top level Ruby program, but is there one for the current method?
Ruby – Get the name of the currently executing method
metaprogrammingreflectionruby
Related Topic
- Regex – How to match all occurrences of a regex
- Java – How to invoke a Java method when given the method name as a string
- C# – How to use reflection to call a generic method
- Ruby – Checking if a variable is defined
- Java – Getting the name of the currently executing method
- Ruby-on-rails – How to understand nil vs. empty vs. blank in Ruby
- Ruby-on-rails – How to get the current absolute URL in Ruby on Rails
- Ruby: Calling class method from instance
Best Answer
Even better than my first answer you can use __method__:
This returns a symbol – for example,
:test_method
. To return the method name as a string, call__method__.to_s
instead.Note: This requires Ruby 1.8.7.