Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 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 :is_human
  9.  
  10. def initialize(is_human = false)
  11. @is_human = is_human
  12. end
  13. end
  14.  
  15. class Mammal < Animal
  16. attr_accessor :produces_milk
  17.  
  18. def initialize(produces_milk = true)
  19. super()
  20. @produces_milk = produces_milk
  21. end
  22. end
  23.  
  24. class Amphibian < Animal
  25. attr_accessor :warm_blooded
  26.  
  27. def initialize(warm_blooded = false)
  28. super()
  29. @warm_blooded = warm_blooded
  30. end
  31. end
  32.  
  33. class Primate < Animal
  34. attr_accessor :num_legs
  35.  
  36. def initialize(num_legs = 2)
  37. super()
  38. @num_legs = num_legs
  39. end
  40. end
  41.  
  42. class Frog < Amphibian
  43. attr_accessor :webbed_feet
  44.  
  45. def initialize(webbed_feet = true)
  46. super()
  47. @webbed_feet = webbed_feet
  48. end
  49. end
  50.  
  51. class Bat < Mammal
  52. attr_accessor :has_wings
  53.  
  54. def initialize(has_wings = true)
  55. super()
  56. @has_wings = has_wings
  57. end
  58. end
  59.  
  60. class Bird < Animal
  61. attr_accessor :lays_eggs
  62.  
  63. def initialize(lays_eggs = true)
  64. super()
  65. @lays_eggs = lays_eggs
  66. end
  67. end
  68.  
  69. class Parrot < Bird
  70. def initialize
  71. super()
  72. end
  73. include Flight
  74. end
  75.  
  76. class Chimpanzee < Primate
  77. def initialize
  78. super()
  79. end
  80. end
  81.  
  82. polly = Parrot.new()
  83. polly.fly
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement