Skip to content

Instantly share code, notes, and snippets.

@foxyblocks
Last active December 21, 2015 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxyblocks/6275670 to your computer and use it in GitHub Desktop.
Save foxyblocks/6275670 to your computer and use it in GitHub Desktop.
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
module CarParts
class Tire
end
end
module BicycleParts
class Tire
end
end
@foxyblocks
Copy link
Author

Example:

lassie = Animals::Dog.new
lassie.talk
#=>  woof

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment