Created
January 22, 2009 06:37
-
-
Save DylanFM/50451 to your computer and use it in GitHub Desktop.
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
def print_ancestor_definitions(cl,method) | |
ancestors = cl.ancestors | |
p ancestors.join(' < ') #Print heirarchy | |
p "Searching..." | |
ancestors.each do |c| | |
if c.instance_methods.include? method | |
p "#{c} defines #{method} as an instance method!" | |
elsif c.singleton_methods.include? method | |
p "#{c} defines #{method} as a singleton method" | |
else | |
p "#{c} doesn't define #{method}" | |
end | |
end | |
end | |
print_ancestor_definitions(Array,'find') | |
# >> "Array < Enumerable < Object < Kernel" | |
# >> "Searching..." | |
# >> "Array defines find as an instance method!" | |
# >> "Enumerable defines find as an instance method!" | |
# >> "Object doesn't define find" | |
# >> "Kernel doesn't define find" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment