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

About this user

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Get the currently running method name in Ruby

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

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS