Never been to DZone Snippets before?

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

Get the currently running method name in Ruby (See related posts)

from: http://www.ruby-forum.com/topic/75258

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


You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts