Created
December 11, 2014 17:04
-
-
Save nybblr/a3a5f1d108f4a78bdf06 to your computer and use it in GitHub Desktop.
Module "inheritance" and ancestor tree.
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
module Fishish | |
def kind | |
"fish#{super}" | |
end | |
end | |
module Dogish | |
def kind | |
"dog#{super}" | |
end | |
end | |
module Catish | |
def kind | |
"cat#{super}" | |
end | |
end | |
class Animal | |
def say | |
puts "I'm a #{kind}!" | |
end | |
def kind | |
" animal" | |
end | |
end | |
class Dogfish < Animal | |
include Fishish | |
include Dogish | |
end | |
dogfish = Dogfish.new | |
dogfish.say # => "I'm a dogfish animal!" | |
p Dogfish.ancestors # => [Dogfish, Dogish, Fishish, Animal, Object, PP::ObjectMixin, Kernel, BasicObject] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment