R
Rahul Kumar
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)
Regards, rkumar
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)
Regards, rkumar