Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Flight
- def fly
- puts "I'm a parrot, I'm flying!"
- end
- end
- class Animal
- attr_reader :name
- def initialize(name)
- @heart = 1
- @name = name
- end
- def heart
- @heart
- end
- end
- class Mammal < Animal
- end
- class Amphibian < Animal
- end
- class Primate < Mammal
- attr_reader
- def initialize(name)
- super(name)
- @legs = 2
- @strength = 10
- end
- def legs
- @legs
- end
- def strength
- @strength
- end
- end
- class Frog < Amphibian
- end
- class Bat < Mammal
- end
- class Bird < Animal
- end
- class Parrot < Bird
- include Flight
- end
- class Chimpanzee < Primate
- def initialize(name)
- super(name)
- @hairy = "very"
- end
- end
- primate1 = Primate.new('Joe')
- chimp11 = Chimpanzee.new('Bob')
- puts "#{chimp11.name} has #{chimp11.heart} heart"
- puts "#{chimp11.name} has #{chimp11.legs} legs"
- puts "#{chimp11.name} has #{chimp11.strength}KG grip strength"
- puts primate1.inspect
- puts chimp11.inspect
- parrot1 = Parrot.new('Hyuk')
- puts parrot1.inspect
- parrot1.fly
- bat1 = Bat.new('yolo')
- puts bat1.inspect
- bat1.fly #Bat doesn't work because I did not include the module Flight in the Bat class or any of its superclasses
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement