Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Flight
- def fly
- puts "I'm a #{self.class}, I'm flying!"
- end
- end
- class Animal
- attr_accessor :num_legs, :size
- def initialize (num_legs, size)
- @num_legs = num_legs
- @size = size
- end
- end
- class Mammal < Animal
- attr_accessor :gives_milk
- def initialize (num_legs, size)
- super(num_legs, size)
- @gives_milk = true
- end
- end
- class Amphibian < Animal
- attr_accessor :cold_blooded
- def initialize (num_legs, size)
- super(num_legs, size)
- @cold_blooded = true
- end
- end
- class Primate < Mammal
- def initialize (num_legs, size)
- super(2, size)
- end
- end
- class Bird < Animal
- include Flight
- attr_accessor :wings
- def initialize (num_legs, size)
- super(2, size)
- @wings = true
- end
- end
- class Frog < Amphibian
- attr_accessor :colour
- def initialize(num_legs, size)
- super(4, size)
- @colour = colour
- end
- end
- class Bat < Mammal
- include Flight
- attr_reader :night
- def initialize(num_legs, size)
- super(2, size)
- @night = true
- end
- end
- class Parrot < Bird
- attr_reader :talks
- def initialize(num_legs, size)
- super(2, size)
- @talks = true
- end
- end
- class Chimpanzee < Primate
- attr_reader :name, :age
- def initialize(num_legs, size, name, age)
- super(2, size)
- @name = name
- @age = age
- end
- end
- @purru = Parrot.new(2, 'big')
- puts @purru.talks
- puts @purru.fly
- @dracul = Bat.new(2, 'small')
- puts @dracul.fly
- @george = Chimpanzee.new(2, 'big', 'georgie', 2)
- puts @george.age
- puts @george.num_legs
- puts @george.name
- @kathy = Animal.new(4, 'big')
- puts @kathy.num_legs
- puts @kathy.size
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement