Even better than my first answer you can use __method__:
class Foo
def test_method
__method__
end
end
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…