Continuing my established tradition of stupid questions, I’m wondering how
I can figure out who sent a message to an object. Couldn’t figure this one
out from the ref manual or the “Programming Ruby (&c)” book. I know
Kernel::caller exists, but it only returns the calling method and line
number in the source, nothing about which object/class the method is
associated to. Being the whiny bastage I am, I’m not satisfied with this,
and I want to find out all sorts of trivial information about the caller of
my methods. I don’t let my methods hang out with delinquent classes
Seriously speaking, I’m just interested in knowing information about the
object that calls method xyz, like so:
class Frobble
…
…
def xyz(value)
if self.caller_class = “Moog” # #caller_class is just an example.
Could be just #caller for example
···
return value/43
else
return value/13
end
end
…
…
end