google 'binding of caller' then
eval 'self', Binding.of_caller
Well, if I understand what I found, it's not what I'm looking for.
Binding.of_caller seems to return the binding of the method which called it.
So let's say I've got this:
class String; def foo; who_called_me ;end;end
class X; def test(obj); obj.foo; end; end;
What I want is:
x = X.new ==> #<X:0xb7d56034>
x.test("Hello") ==> #<X:0xb7d56034>
instead of
x.test("Hello") ==> "Hello"
which is what I get, if I replace who_called_me with
eval 'self', binding.of_caller
It doesn't seem possible to get what I'm looking for using the
technique used in Binding.of_caller which is to set a trace to detect
when we return to the caller (or is it from the caller). To do what
I'm talking about seems to require examining the current call stack to
get the receiver of the preceding message.
It looks like the best you can do in ruby is to get a backtrace with
Kernel#caller, or by raising and rescuing an exception, only gives
strings describing where you were in the source, but with no access to
the actual receiver objects.
--
Rick DeNatale
My blog on Ruby
http://talklikeaduck.denhaven2.com/
IPMS/USA Region 12 Coordinator
http://ipmsr12.denhaven2.com/
Visit the Project Mercury Wiki Site
http://www.mercuryspacecraft.com/