Thursday, 5 September 2013

How to get the caller object name in ruby?

How to get the caller object name in ruby?

Frequently, the same method X gets called from different objects A, B, C.
Is it possible to get a name of the caller object(A, B, C) from inside
method X
eg :
class sample
def method
p "what needs to be done here????"
end
end
n1=sample.new
n2=sample.new
n1.method ==> expected output is to print n1
n2.method ==> expected output is to print n2

No comments:

Post a Comment