From: Sean O'Halpin Date: 2006-07-11T06:31:17+09:00 Subject: Re: Reflection to get method name from within method? On 7/10/06, Ezra Zygmuntowicz wrote: > Friends- > > Is there anyway to use reflection or someother technique to get the > name of a method from within the method when it is running? > > So if I had this: > > def foo > #some magick incantation here that returns the name of the method > "foo" > end > > > Thanks- > -Ezra > You could use something like this: def method_called caller[0].match(/`([^']+)/).captures[0] end def test_me p method_called end test_me #=> "test_me" I don't know of any other way (unless perhaps you can get this info via ParseTree or evil.rb). Regards, Sean