Last active
May 30, 2016 21:09
-
-
Save McTano/e7c90d179a542858865fdc58ffeda456 to your computer and use it in GitHub Desktop.
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 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