Last active
November 30, 2020 19:53
-
-
Save jaredcwhite/e45149952cb00a0903d49da860a47028 to your computer and use it in GitHub Desktop.
Monkeypatch to find Ruby methods defined within local source tree
This file contains hidden or 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 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