How to get the name of the calling method?
Use caller_locations(1,1)[0].label
(for ruby >= 2.0)
Edit: My answer was saying to use __method__
but I was wrong, it returns the current method name.
puts caller[0]
or perhaps...
puts caller[0][/`.*'/][1..-2]
In Ruby 2.0.0, you can use:
caller_locations(1,1)[0].label
It's much faster than the Ruby 1.8+ solution:
caller[0][/`([^']*)'/, 1]
Will get included in backports
when I get the time (or a pull request!).