Get the currently running method name in Ruby
Author: Robert Klemme
module Kernel private def this_method_name caller[0] =~ /`([^']*)'/ and $1 end end class Foo def test_method this_method_name end end puts Foo.new.test_method # => test_method
DZone Snippets > ntk > current
12551 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
module Kernel private def this_method_name caller[0] =~ /`([^']*)'/ and $1 end end class Foo def test_method this_method_name end end puts Foo.new.test_method # => test_method