Created
April 25, 2018 22:34
-
-
Save budu/2d3f2b560d40c5c143f116fdf43e9d3b to your computer and use it in GitHub Desktop.
When you need to figure out what methods are defined at which point in the class hierarchy.
This file contains 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
Object.class_eval do | |
def hierarch(n = 1) | |
klass_and_ancestry = self.class.ancestors[(n - 1)..-1] | |
klass, *ancestry = klass_and_ancestry | |
to_klass_methods = methods - ancestry.flat_map(&:instance_methods) | |
"#{klass}: #{to_klass_methods}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment