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 name of the current method in Ruby (See related posts)

Found at http://nubyonrails.com/articles/2006/08/04/seattle-rbbq

def method_name
  if  /`(.*)'/.match(caller.first)
    return $1
  end
  nil
end

def blah
  puts method_name
end

blah  # => 'blah'

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


Click here to browse all 5059 code snippets

Related Posts