Skip to content

Instantly share code, notes, and snippets.

@McTano
Last active May 30, 2016 21:09
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 McTano/e7c90d179a542858865fdc58ffeda456 to your computer and use it in GitHub Desktop.
Save McTano/e7c90d179a542858865fdc58ffeda456 to your computer and use it in GitHub Desktop.
module Flight
def fly
"I'm a #{self.class}, I'm flying!"
end
end
class Animal
def initialize
@num_legs = 4
end
attr_reader :num_legs
def talks?
false
end
end
class Mammal < Animal
def warm_blooded?
true
end
def num_arms
4 - @num_legs
end
end
class Bat < Mammal
include Flight
def initialize
@num_legs = 2
end
end
class Primate < Mammal
def initialize
@num_legs = 2
end
end
class Chimpanzee < Primate
end
class Amphibian < Animal
def warm_blooded?
false
end
end
class Frog < Amphibian
end
class Bird < Animal
include Flight
def initialize
@num_legs = 2
@num_wings = 2
end
def num_wings
@num_wings
end
end
class Parrot < Bird
def talks?
true
end
end
p Parrot.new.talks?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment