On Wed, Jul 4, 2012 at 9:57 AM, Bartosz DziewoƄski <[email protected]> wrote:
> You can use the `local_variables` method to get a list of local
> variables in current scope. So maybe something like this:
>
> $values_at_time = {}
>
> set_trace_func proc { |event, file, line, id, binding, classname|
>         if event == "line"
>                 $values_at_time[line] = binding.eval('local_variables.map{|v| 
> [v,
> eval(v.to_s)] }')
>         end
> }
>
> a = 5
> stuff = 'asd'
> a += 8
>
> set_trace_func nil
> pp $values_at_time

That still suffers from the issue of changes in referenced object
which will modify the stored state.  Even adding to an Array will
change history.  As I said earlier you would need to store a complete
object graph, something like

$values_at_time = {}

set_trace_func proc { |event, file, line, id, binding, classname|
        if event == "line"
                $values_at_time[line] =
Marshal.dump(binding.eval("local_variables").inject({})
{|h,v|h[v]=binding.eval(v.to_s);h})
        end
}

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to