Skip to content

Instantly share code, notes, and snippets.

@jaredcwhite
Last active November 30, 2020 19:53
Show Gist options
  • Save jaredcwhite/e45149952cb00a0903d49da860a47028 to your computer and use it in GitHub Desktop.
Save jaredcwhite/e45149952cb00a0903d49da860a47028 to your computer and use it in GitHub Desktop.
Monkeypatch to find Ruby methods defined within local source tree
module InstanceMethodsSource
refine Object do
def self.instance_methods_sourced_locally
meths = instance_methods
meths_hash = Hash.new
meths.each do |meth|
soc = instance_method(meth).source_location
if !soc.nil? && soc[0].start_with?(Dir.pwd)
meths_hash[meth] = soc
end
end
meths_hash
end
def methods_sourced_locally
meths = methods
meths_hash = Hash.new
meths.each do |meth|
soc = method(meth).source_location
if !soc.nil? && soc[0].start_with?(Dir.pwd)
meths_hash[meth] = soc
end
end
meths_hash
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment