Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Flight
- def fly
- puts "I am a #{self.class.name}, I'm flying!"
- end
- end
- class Animal
- attr_reader :can_sleep, :can_eat
- def initialize
- @can_sleep = true
- @can_eat = true
- end
- end
- class Mammal < Animal
- attr_reader :warm_blooded
- def initialize
- super
- @warm_blooded = true
- end
- end
- class Amphibian < Animal
- attr_reader :hands, :legs
- def initialize
- super
- @hands = 2
- @legs = 2
- end
- end
- class Primate < Mammal
- def initialize
- super
- end
- end
- class Frog < Amphibian
- attr_reader :can_jump
- def initialize
- super
- @can_jump = true
- end
- end
- class Bat < Mammal
- include Flight
- def initialize
- super
- @legs = 2
- end
- end
- class Bird < Animal
- attr_reader :can_fly
- include Flight
- def initialize
- super
- @can_fly = true
- end
- end
- class Parrot < Bird
- include Flight
- def initialize
- super
- @can_speak = true
- end
- end
- class Chimpanzee < Primate
- end
- Bird.new.fly
- puts Bird.new.can_fly
- Parrot.new.fly
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement