Last active
April 5, 2016 00:59
-
-
Save kiefer136/921648c42dbda49ec6c7ba817da8361b 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
require_relative "./animalmodule" | |
class Animal | |
attr_reader :breath_air | |
attr_reader :num_legs | |
def initialize | |
@breath_air = true | |
@num_legs = 0 | |
super | |
end | |
end | |
class Mammal < Animal | |
attr_reader :has_womb | |
def initialize | |
@has_womb = true | |
super | |
end | |
end | |
class Bat < Mammal | |
attr_reader :has_wings | |
include Flight | |
def initialize | |
@has_wings = true | |
@num_legs = 2 | |
super | |
end | |
end | |
class Amphibian < Animal | |
attr_reader :lays_eggs | |
def initialize | |
@lays_eggs = true | |
super | |
end | |
end | |
class Frog < Amphibian | |
def initialize | |
super | |
@has_legs = 4 | |
end | |
end | |
class Primate < Mammal | |
def initialize | |
super | |
@num_legs = 2 | |
end | |
end | |
class Chimpanzee < Primate | |
end | |
class Bird < Animal | |
attr_reader :has_wings | |
attr_reader :has_wings | |
attr_reader :has_feathers | |
include Flight | |
def initialize | |
@has_feathers = true | |
@lays_eggs = true | |
@has_wings = true | |
super | |
@num_legs = 2 | |
end | |
end | |
class Parrot < Bird | |
end | |
bat = Bat.new | |
parrot = Parrot.new | |
p parrot.fly | |
p bat.fly | |
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 | |
attr_accessor :fly | |
def fly | |
puts "I'm a #{self.class}, I'm flying!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment