Last active
February 10, 2017 08:43
-
-
Save roniegh/88acf808f76c31735260a7a410ffda18 to your computer and use it in GitHub Desktop.
Find where a variable is over-written with a different value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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