From: Robert Klemme Date: 2012-07-04T17:49:08+09:00 Subject: Re: Using binding + set trace func to capture execution state On Wed, Jul 4, 2012 at 9:57 AM, Bartosz DziewoƄski 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/