Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'pry'
- module Flight
- def fly
- puts "I'm a #{self.name} and I fly."
- end
- end
- class Animal
- attr_reader :breathes, :multiplies, :name
- def initialize(breathes, multiplies, name)
- @breathes = breathes
- @multiplies = multiplies
- @name = name
- end
- end
- class Mammal < Animal
- attr_accessor :num_legs
- attr_reader :warm_blooded
- def initialize(breathes, multiplies, name, warm_blooded, num_legs)
- super(breathes, multiplies, name)
- @warm_blooded = true
- @num_legs = num_legs
- end
- end
- class Primate < Mammal
- attr_reader :opozable_thumb
- def initialize(breathes, multiplies, name, warm_blooded, num_legs, opozable_thumb)
- super(breathes, multiplies, name, warm_blooded, num_legs)
- @opozable_thumb = true
- end
- end
- class Chimpanzee < Primate
- end
- class Bat < Mammal
- include Flight
- attr_accessor :wings
- def initialize(breathes, multiplies, name, warm_blooded, num_legs, wings)
- super(breathes, multiplies, name, warm_blooded, num_legs)
- @wings = 2
- end
- end
- class Amphibian < Animal
- attr_reader :breaths_under_water
- def initialize(breathes, multiplies, name, breaths_under_water)
- super(breathes, multiplies, name)
- @breaths_under_water = true
- end
- end
- class Frog < Amphibian
- attr_accessor :nocturnal
- def initialize(breathes, multiplies, name, breaths_under_water, nocturnal)
- super(breathes, multiplies, name, breaths_under_water)
- @nocturnal = nocturnal
- end
- end
- class Bird < Animal
- include Flight
- attr_accessor :talks
- def initialize(breathes, multiplies, name, talks)
- super(breathes, multiplies, name)
- @talks = talks
- end
- end
- class Parrot < Bird
- include Flight
- attr_accessor :color
- def initialize(breathes, multiplies, name, talks, color)
- super(breathes, multiplies, name, talks)
- @color = color
- end
- end
- jimmy = Parrot.new("breaths", "multiplies", "parrot", "immitates humans", "red")
- puts jimmy.fly
- polly = Bat.new("breaths", "multiplies", "bat", true, 2, 2)
- puts polly.fly
- # breathes, multiplies, name, warm_blooded, num_legs, wings
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement