Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Flight
- attr_accessor(:flight_speed)
- def fly
- puts "I am a #{self.class}, I am flying at #{flight_speed} miles per hour"
- end
- end
- class Animal
- attr_accessor(:brain)
- def initialize(brain)
- @brain = brain
- end
- end
- class Mammal < Animal
- def initialize(brain)
- super(brain)
- end
- def live_birth
- puts "I have live birth"
- end
- end
- class Amphibian < Animal
- def initialize(brain)
- super(brain)
- end
- def lay_egg
- puts "I can lay an egg"
- end
- end
- class Primate < Mammal
- def initialize(brain)
- super(brain)
- @legs = 2
- end
- def land_dweller
- puts "I like the land"
- end
- end
- class Frog < Amphibian
- def initialize(brain)
- super(brain)
- end
- end
- class Chimpanzee < Primate
- def initialize(brain)
- super(brain)
- end
- def tools
- puts "I can use tools"
- end
- end
- class Bat < Animal
- include Flight
- def initialize(brain)
- super(brain)
- end
- end
- class Parrot < Animal
- include Flight
- def initialize(brain)
- super(brain)
- end
- end
- bat1 = Bat.new(true)
- bat1.flight_speed = 2
- bat1.fly
- parrot1 = Parrot.new(true)
- parrot1.flight_speed = 7
- parrot1.fly
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement