From: Ammar Ali Date: 2010-11-02T19:56:36+09:00 Subject: Re: get method name when aliasing On Tue, Nov 2, 2010 at 11:13 AM, Rahul Kumar wrote: > I'd like to know the current method name or alias used, as follows: > > def write >   m = __method__ >   flag = (m == "write!" ? true : false) > >   some processing based on flag > > end > alias :write! write > > So if user calls write! flag is true, else false. > > __method__ gives original name not alias used. > > In irb, i tried: caller[0] =~ /`([^']*)'/ and $1 > but this returns "irb_binding". > > I might land up having quite a lot of such methods, so i'd rather not > make multiple methods with "!" calling the original ones. > > (btw, i've checked earlier threads: > http://www.ruby-forum.com/topic/75258) > If I understood your purpose correctly, then this recent thread sheds some light on aliases: http://www.ruby-forum.com/topic/232274 And this gist might be of interest as well: http://gist.github.com/631102 However, IMHO, if one needs such functionality, then it is probably a sign that the design needs review. I put this gist together to discover aliases and satisfy my curiosity, only. Regards, Ammar