我试图在废墟中写一小gger。 每次都出现变化。 我事先不知道变量。
At the moment I m trying set_trace_func but it seems to execute before each line, rather than after each line eg;
set_trace_func proc { |event, file, line, id, binding, classname|
if file == "(eval)"
printf "%8s %s:%-2d %10s %8s
", event, file, line, id, classname
args = binding.eval("local_variables").inject({}) do |vars, name|
value = binding.eval name.to_s
vars[name] = value unless vars.nil?
vars
end
puts args.inspect
end
}
eval("blah = 4
rar = 3
")
set_trace_func(nil)
当我执行时,我就跑了。
n@VirtualBox:~$ ruby blah.rb
line (eval):1
{:blah=>nil, :rar=>nil}
line (eval):2
{:blah=>4, :rar=>nil}
n@VirtualBox:~$
This is not what I want - it s not showing the assignment to rar. Is there a better way to do this? As a hack, I added one last statement to the eval eg.
eval("blah = 4
rar = 3
nil
")
but that doesn t fix the problem when it comes to loops etc.
我愿获得一项产出,说明哪一线变化,以及它改变了方向。