Last active
December 21, 2015 08:08
-
-
Save foxyblocks/6275670 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 AnimalKingdom | |
def type | |
'Animal' | |
end | |
end | |
module PlantKingdom | |
def type | |
'Plant' | |
end | |
end | |
module Commands | |
def sit | |
puts 'sitting' | |
end | |
def stay | |
end | |
def roll_over | |
end | |
end | |
class Dog | |
include Commands | |
extend AnimalKingdom | |
def talk | |
puts 'woof' | |
end | |
end | |
class Cat | |
include Commands | |
extend AnimalKingdom | |
def talk | |
puts 'meow' | |
end | |
end | |
lassie = Dog.new | |
lassie.sit | |
#=> sitting | |
mittens = Cat.new | |
mittens.sit | |
#=> sitting | |
Dog.type | |
#=> Animal | |
Cat.type | |
#=> Animal | |
class AppleTree | |
extend PlantKingdom | |
end | |
AppleTree.type | |
#=> Plant | |
AppleTree.extend(AnimalKingdom) | |
AppleTree.type | |
#=> Animal |
This file contains hidden or 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 CarParts | |
class Tire | |
end | |
end | |
module BicycleParts | |
class Tire | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: