Skip to content

Instantly share code, notes, and snippets.

@jcoglan
Created January 31, 2019 00:08
Show Gist options
  • Save jcoglan/6490a2c2232239c46bf91fec86f752d3 to your computer and use it in GitHub Desktop.
Save jcoglan/6490a2c2232239c46bf91fec86f752d3 to your computer and use it in GitHub Desktop.
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