Created
May 30, 2016 20:57
-
-
Save cody-code-wy/91c1fa6d8994ac26fa62124e9962adbf 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 | |
puts "I'm a #{self.class.name}, I'm flying!" | |
end | |
end | |
class Animal | |
@name = "Animal" | |
attr_reader :name | |
end | |
class Mammal < Animal | |
@name = "Mammal" | |
def is_warm_blooded? | |
true | |
end | |
end | |
class Amphibian < Animal | |
@name = "Amphibian" | |
def is_warm_blooded? | |
false | |
end | |
end | |
class Primate < Mammal | |
@name = "Primate" | |
@num_legs = 2 | |
end | |
class Frog < Amphibian | |
@name = "Frog" | |
@num_legs = 4 | |
end | |
class Bat < Mammal | |
include Flight | |
@name = "Bat" | |
@num_legs = 2 | |
end | |
class Bird < Animal | |
include Flight | |
@name = "Bird" | |
@num_legs = 2 | |
def is_warm_blooded? | |
true | |
end | |
end | |
class Parrot < Bird | |
@name = "Parrot" | |
end | |
class Chimpanzee < Primate | |
@name = "Chimpanzee" | |
end | |
Parrot.new.fly | |
Bat.new.fly | |
puts Parrot.new.is_warm_blooded? | |
puts Chimpanzee.new.is_warm_blooded? | |
puts Frog.new.is_warm_blooded? | |
puts Parrot.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment