From: Ace Suares Date: 2010-03-10T12:21:23+09:00 Subject: Re: using the current method name within current method Robert Klemme wrote: > These methods are typically put into Kernel and made private. Also, you > don't check whether the RX actually matches. I'd also prefer to change > the RX to a more efficient one. So that would give > > module Kernel > private > def this_method > caller[0] =~ /`([^']*)'/ and $1 > end > end > > Kind regards > > robert Excellent! I was searching for this for a long time. 'what method called this method' or 'how to find out which method called this method ?' So, here's one: module Kernel private def this_method caller[0] =~ /`([^']*)'/ and $1 end def calling_method caller[1] =~ /`([^']*)'/ and $1 end end Example: def a b end def b puts "this method: " + this_method puts "calling method: " + calling_method end calling 'a' will output this method: b calling method: a Thx! -- Posted via http://www.ruby-forum.com/.