i wasn't aware of set_trace_func.
good news: it gives you a binding.
bad news: the binding appears to be largely opaque except
for a few "windows" into the binding, such as,

   eval("local_variables", binding)

and, of course, global_variables and 'self', but maybe that's all
there is to a binding.

So your idea of just pushing and popping bindings is probably
sufficient.
Thanks. Interesting idea.



Robert Klemme wrote:

> Lou Vanek <vanek / acd.net> wrote:
> 
>> if you want to wade into the deep end, I would like a method that
>> would tell me about everything that is in scope when the method is 
>> called,
>> and classify the objects-in-scope as instance variables, class
>> variables, class names, global constants, local variables, module
>> names--whatever they might be. Symbol.all_symbols is just a tease.
>>
>> The next thing i would like to do is to be able to "unwind" the
>> scope by going "up" one level and perform the same symbol dump as
>> defined above, except with the new scope. Recurse until at top level.
>> Being able to filter on any particular class of object would just be
>> icing.
>> Not even sure if this is possible, but it would sure be educational.
> 
> 
> You can get quite far with set_trace_func:
> http://ruby-doc.org/core/classes/Kernel.html#M001978
> 
> Just store the binding on a stack for all events like "call" and remove 
> it for "return".
> 
> I'm sure with a decent C extension this will be more efficient and 
> probably more feature rich.
> 
> Kind regards
> 
>    robert