Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. module Flight
  2. def fly
  3. puts "I'm a #{self.class}, I'm flying!"
  4. end
  5. end
  6.  
  7. class Animal
  8. attr_accessor :num_legs, :size
  9. def initialize (num_legs, size)
  10. @num_legs = num_legs
  11. @size = size
  12. end
  13. end
  14.  
  15. class Mammal < Animal
  16. attr_accessor :gives_milk
  17. def initialize (num_legs, size)
  18. super(num_legs, size)
  19. @gives_milk = true
  20. end
  21. end
  22.  
  23. class Amphibian < Animal
  24. attr_accessor :cold_blooded
  25. def initialize (num_legs, size)
  26. super(num_legs, size)
  27. @cold_blooded = true
  28. end
  29. end
  30.  
  31. class Primate < Mammal
  32.  
  33. def initialize (num_legs, size)
  34. super(2, size)
  35. end
  36. end
  37.  
  38. class Bird < Animal
  39. include Flight
  40. attr_accessor :wings
  41. def initialize (num_legs, size)
  42. super(2, size)
  43. @wings = true
  44. end
  45. end
  46.  
  47. class Frog < Amphibian
  48. attr_accessor :colour
  49. def initialize(num_legs, size)
  50. super(4, size)
  51. @colour = colour
  52. end
  53. end
  54.  
  55. class Bat < Mammal
  56. include Flight
  57. attr_reader :night
  58. def initialize(num_legs, size)
  59. super(2, size)
  60. @night = true
  61. end
  62. end
  63.  
  64. class Parrot < Bird
  65. attr_reader :talks
  66. def initialize(num_legs, size)
  67. super(2, size)
  68. @talks = true
  69. end
  70. end
  71.  
  72. class Chimpanzee < Primate
  73. attr_reader :name, :age
  74. def initialize(num_legs, size, name, age)
  75. super(2, size)
  76. @name = name
  77. @age = age
  78. end
  79. end
  80.  
  81. @purru = Parrot.new(2, 'big')
  82. puts @purru.talks
  83. puts @purru.fly
  84.  
  85. @dracul = Bat.new(2, 'small')
  86. puts @dracul.fly
  87.  
  88. @george = Chimpanzee.new(2, 'big', 'georgie', 2)
  89. puts @george.age
  90. puts @george.num_legs
  91. puts @george.name
  92.  
  93. @kathy = Animal.new(4, 'big')
  94. puts @kathy.num_legs
  95. puts @kathy.size
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement