Skip to content

Instantly share code, notes, and snippets.

@budu
Created April 25, 2018 22:34
Show Gist options
  • Save budu/2d3f2b560d40c5c143f116fdf43e9d3b to your computer and use it in GitHub Desktop.
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.
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