Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require "set"
mods = Class.ancestors +
Method.ancestors +
UnboundMethod.ancestors
reserved = %i[
==
===
=~
caller
first
split
]
project = %r{/jit/lib/}
$called = SortedSet.new
def exit(*)
File.open("calls.log", "w") do |f|
$called.each { |thing| f.puts thing.inspect }
end
super
end
ObjectSpace.each_object(Module) do |mod|
next if mods.include?(mod)
mod.instance_methods(false).each do |m_name|
next if reserved.include?(m_name)
method = mod.instance_method(m_name)
next if method.source_location.to_s =~ project
key = [mod.inspect, m_name]
mod.module_eval do
define_method m_name do |*args, &blk|
file = caller.first.split(":").first
$called.add(key) if file != __FILE__ and file =~ project
method.bind(self).call(*args, &blk)
end
end
rescue FrozenError
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment