例如:
def example_method puts method_name end #=> "example_method"
试试这个方法,从 here
module Kernel private def current_method_name caller[0] =~ /`([^']*)'/ and $1 end end class Foo def test_method current_method_name # "test_method" end end
here 本强调。