Skip to content

Instantly share code, notes, and snippets.

@roniegh
Last active February 10, 2017 08:43
Show Gist options
  • Save roniegh/88acf808f76c31735260a7a410ffda18 to your computer and use it in GitHub Desktop.
Save roniegh/88acf808f76c31735260a7a410ffda18 to your computer and use it in GitHub Desktop.
Find where a variable is over-written with a different value
class Abc
def initialize
@thing = {"foo" => "bar"}
end
end
$stack = [{:config => {}}]
set_trace_func lambda { |event, file, line, id, binding, classname|
printf("%8s %s:%-2d %10s %8s\n", event, file, line, id, classname)
if binding.eval("local_variables").include?(:config)
_new = binding.eval("config")
if _new && ($stack.last[:config][:value] != _new.inspect)
$stack << {
:config => {
:self => binding.eval("self"),
:source => "#{file}:#{line}",
:value => _new.inspect
}
}
end
end
}
config = Abc.new
config.instance_variable_set(:@thing, 123)
config = "foo"
set_trace_func nil
puts $stack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment