Skip to content

Instantly share code, notes, and snippets.

@ayosec
Created January 19, 2011 04:26
Show Gist options
  • Save ayosec/785687 to your computer and use it in GitHub Desktop.
Save ayosec/785687 to your computer and use it in GitHub Desktop.
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