From: Mike Nelson Date: 2006-05-18T03:42:19+09:00 Subject: Re: Method name uncutstone wu wrote: > Dave Burt wrote: >> Mark Volkmann wrote: >>> name = caller(0).first.split.last >>> >>> This gives it to you with single quotes around it which you may want >>> to strip off. >> >> Does this work? >> >> def __FUNCTION__ >> caller(1).first[/ `(.*)'\Z/, 1] >> end >> >> Cheers, >> Dave > > What if I am at the outmost level? > I cannot get a function name , just got something like this: > test.rb:2546 > > It may not be a perfect solution. It seems to work properly for me on the outermost level. def __FUNCTION__ caller(1).first[/ `(.*)'\Z/, 1] end def test_method puts "i'm in '#{__FUNCTION__}'" end test_method puts "outer: i'm in '#{__FUNCTION__}'" produces, i'm in 'test_method' outer: i'm in '' -- Posted via http://www.ruby-forum.com/.