Skip to content

Instantly share code, notes, and snippets.

@DylanFM
Created January 22, 2009 06:37
Show Gist options
  • Save DylanFM/50451 to your computer and use it in GitHub Desktop.
Save DylanFM/50451 to your computer and use it in GitHub Desktop.
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