Ezra Zygmuntowicz
7/10/2006 9:47:00 PM
On Jul 10, 2006, at 2:31 PM, Sean O'Halpin wrote:
> On 7/10/06, Ezra Zygmuntowicz <ezmobius@gmail.com> 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
>
Ok thanks Sean, that will work for what I need to do.
Cheers-
-Ezra