Created
January 19, 2011 04:26
-
-
Save ayosec/785687 to your computer and use it in GitHub Desktop.
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
module Kernel | |
def trace_instances(traced_class = ActiveRecord::Base, &block) | |
instances = [] | |
set_trace_func(proc do |event, file, line, id, binding, classname| | |
if event == "line" | |
obj = eval("self", binding) | |
instances << obj if obj.kind_of?(traced_class) | |
end | |
end) | |
block.call | |
ensure | |
set_trace_func nil | |
instances.uniq! | |
puts "Traced instances: #{instances.size}" | |
instances.each {|inst| puts "> #{inst.inspect}" } | |
instances.clear | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment