Skip to content

Instantly share code, notes, and snippets.

@jimmycuadra
Created March 14, 2011 18:16
Show Gist options
  • Select an option

  • Save jimmycuadra/869577 to your computer and use it in GitHub Desktop.

Select an option

Save jimmycuadra/869577 to your computer and use it in GitHub Desktop.
Determining which ancestor defines a particular method
# determining where a method was defined
module Organic
def organic?
true
end
end
class Fruit
def edible?
true
end
end
class OrganicApple < Fruit
include Organic
def color
"red"
end
end
apple = OrganicApple.new
puts apple.method(:color).owner # => OrganicApple
puts apple.method(:edible?).owner # => Fruit
puts apple.method(:organic?).owner # => Organic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment