Skip to content

Instantly share code, notes, and snippets.

@data-doge
Created February 16, 2015 07:09
Show Gist options
  • Save data-doge/af42df0b06274ae0d4ab to your computer and use it in GitHub Desktop.
Save data-doge/af42df0b06274ae0d4ab to your computer and use it in GitHub Desktop.
design-drill-classical-inheritance-challenge
module SuperPowers
attr_accessor :magic_points
def initialize
super
@magic_points = 0
end
def use_laser_vision
@magic_points += 1
puts "It's Laser Time AHHH YEAHHH"
end
end
class Animal
def initialize
@stomach = []
end
def eat!(food)
@stomach << food
end
def hungry?
@stomach.empty?
end
def deficate!
@stomach = []
end
end
class Mammal < Animal
attr_reader :warm_blooded, :spine
def initialize
super
@warm_blooded = true
@spine = true
end
end
class Primate < Mammal
attr_reader :number_of_legs, :oppressed
def initialize
super
@number_of_legs = 2
@oppressed = true
end
def walk!
puts "I am walking"
end
def reclaim_planet_from_humans!
@oppressed = false
end
end
class Bat < Mammal
include SuperPowers
attr_reader :number_of_wings
def initialize
super
@number_of_wings = 2
end
def fly!
puts "I am flying!"
end
end
class Amphibian < Animal
attr_reader :warm_blooded
def initialize
super
@warm_blooded = false
end
end
class Chimpanzee < Primate
def initialize
super
end
end
class Frog < Amphibian
def hop!
puts "I am hopping"
end
end
chimp = Chimpanzee.new
chimp.eat!("banana")
puts chimp.hungry? == false
chimp.deficate!
puts chimp.hungry? == true
puts chimp.spine == true
puts chimp.warm_blooded == true
puts chimp.number_of_legs == 2
chimp.reclaim_planet_from_humans!
puts chimp.oppressed == false
chimp.walk!
bat = Bat.new
bat.eat!("blood")
puts bat.hungry? == false
bat.deficate!
puts bat.hungry? == true
puts bat.number_of_wings == 2
puts bat.warm_blooded == true
puts bat.spine == true
bat.fly!
bat.use_laser_vision
puts bat.magic_points == 1
frog = Frog.new
frog.eat!("fly")
puts frog.hungry? == false
frog.deficate!
puts frog.hungry? == true
puts frog.warm_blooded == false
frog.hop!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment