I would like to dynamically determine the class in which the current method was defined.
Here is a static example of what I'm trying to do:
class A def foo puts "I was defined in A" end end class B < A def foo puts "I was defined in B" super end end A.new.foo
How to replace A
and B
in the above lines with a dynamic expression?
Apparently, #{self.class}
not working. (he will print I was defined in B
twice for B
)
I suspect the answer is “you can't,” but maybe I'm missing something.
source share