Skip to content

Instantly share code, notes, and snippets.

@shinobcrc
Created June 27, 2016 15:27
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 shinobcrc/018cf073f9a3d907cc4828ffcc0b98e2 to your computer and use it in GitHub Desktop.
Save shinobcrc/018cf073f9a3d907cc4828ffcc0b98e2 to your computer and use it in GitHub Desktop.
module Flight
def fly
puts "I'm a #{self.class}, I'm flying"
end
end
class Animal
attr_reader :num_legs, :warm_blooded
def initialize(num_legs, warm_blooded)
@num_legs = num_legs
@warm_blooded = warm_blooded
end
end
class Mammal < Animal
attr_reader :has_hair, :has_vertebrate
def initialize(num_legs, warm_blooded, has_hair, has_vertebrate)
super(num_legs, warm_blooded)
@num_legs = 2
@warm_blooded = true
@has_hair = has_hair
@has_vertebrate = has_vertebrate
end
end
class Bat < Mammal
attr_reader :nocturnal
include Flight
def initialize(num_legs, warm_blooded, has_hair, has_vertebrate, nocturnal)
super(num_legs, warm_blooded, has_hair, has_vertebrate, nocturnal)
@nocturnal = nocturnal
end
end
class Primate < Mammal
attr_reader :has_thumbs
def initialize(num_legs, warm_blooded, has_hair, has_vertebrate, has_thumbs)
super(num_legs, warm_blooded, has_hair, has_vertebrate)
@has_thumbs = has_thumbs
end
end
class Chimpanzee < Primate
attr_reader :highly_intelligent
def intialize(num_legs, warm_blooded, has_hair, has_vertebrate, has_thumbs, highly_intelligent)
super(num_legs, warm_blooded, has_hair, has_vertebrate, has_thumbs)
@highly_intelligent = highly_intelligent
end
end
class Amphibian < Animal
attr_reader :permeable_skin
def initialize(num_legs, warm_blooded, permeable_skin)
super(num_legs, warm_blooded)
@permeable_skin = permeable_skin
end
end
class Frog < Amphibian
attr_reader :long_legs
def intialize(num_legs, warm_blooded, permeable_skin, long_legs)
super(num_legs, warm_blooded, permeable_skin, long_legs)
@num_legs = 4
@long_legs = long_legs
end
end
class Bird < Animal
attr_reader :has_wings
include Flight
def initialize(num_legs, warm_blooded, has_wings)
super(num_legs, warm_blooded)
@has_wings = has_wings
end
end
class Parrot < Bird
attr_reader :can_repeat_words
include Flight
def initialize(num_legs, warm_blooded, has_wings, can_repeat_words)
super(num_legs, warm_blooded, has_wings)
@can_repeat_words = can_repeat_words
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment