From: Logan Capaldo Date: 2006-08-01T02:57:44+09:00 Subject: Re: using the current method name within current method On Jul 31, 2006, at 4:25 AM, Robert Klemme wrote: > Matt Todd wrote: >> If you wanted to modularize it just for the sake of it, you could do >> something similar to the following: >> module CurrentMethodName >> def this_method >> caller[0]=~/`(.*?)'/ >> $1 >> end >> end > > You can rewrite that as > > def this_method > caller[0][/`([^']*)'/, 1] > end > > and thusly avoid the global variable. > > Kind regards > > robert > I have a sneaking suspicion he might have done it with the global variable (although $1 isn't really global) on purpose, since =~ / literal/ is the fastest way to do a regexp.