Skip to content

Instantly share code, notes, and snippets.

@nybblr
Created December 11, 2014 17:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nybblr/a3a5f1d108f4a78bdf06 to your computer and use it in GitHub Desktop.
Save nybblr/a3a5f1d108f4a78bdf06 to your computer and use it in GitHub Desktop.
Module "inheritance" and ancestor tree.
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