Ruby: a nice way to get name of current method you’re in:

2009 November 16

This is a nice extension to get the name of the method you’re currently in (Ruby < 1.9)

module Kernel
   private
   def this_method
     caller[0] =~ /`([^']*)'/ and $1
   end
end

for Ruby >= 1.9 you can uses this:

module Kernel
   private
   def this_method
     __method__
   end
end

[see Stack Over Flow as well]

No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS