I ask b/c I was wondering if getting the binding of super is any way feasible.
"super" is a method call that calls into the base class.
What you want isn't to get the "binding of super" (which is really
meaningless), but the binding for the block that is created when you
call a method. There isn't any good way to do this, but you can hack it
with set_trace_func:
require 'thread'
def call_and_get_binding(obj, method, *args, &block)
critical = Thread.critical
Thread.critical = true
begin
binding = nil
set_trace_func proc { |*x|
if x[0] == "call" then
set_trace_func nil
binding = x[4]
end
}
result = obj.__send__(method, *args, &block)
return binding, result
ensure
Thread.critical = critical
end
end
def foo
x = 1
end
binding, result = call_and_get_binding(self, :foo)
p eval("x", binding) #=> 1
Now why you'd want to do this is beyond me, but have fun...
Paul