Advertisement
Guest User

Untitled

a guest
May 30th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. module Flight
  2. def fly
  3. puts "I am a #{self.class.name}, I'm flying!"
  4. end
  5. end
  6.  
  7. class Animal
  8. attr_reader :can_sleep, :can_eat
  9. def initialize
  10. @can_sleep = true
  11. @can_eat = true
  12. end
  13. end
  14.  
  15. class Mammal < Animal
  16. attr_reader :warm_blooded
  17.  
  18. def initialize
  19. super
  20. @warm_blooded = true
  21. end
  22. end
  23.  
  24. class Amphibian < Animal
  25. attr_reader :hands, :legs
  26. def initialize
  27. super
  28. @hands = 2
  29. @legs = 2
  30. end
  31. end
  32.  
  33. class Primate < Mammal
  34. def initialize
  35. super
  36. end
  37. end
  38.  
  39. class Frog < Amphibian
  40. attr_reader :can_jump
  41. def initialize
  42. super
  43. @can_jump = true
  44. end
  45. end
  46.  
  47. class Bat < Mammal
  48. include Flight
  49. def initialize
  50. super
  51. @legs = 2
  52. end
  53. end
  54.  
  55. class Bird < Animal
  56. attr_reader :can_fly
  57. include Flight
  58. def initialize
  59. super
  60. @can_fly = true
  61. end
  62. end
  63.  
  64. class Parrot < Bird
  65. include Flight
  66. def initialize
  67. super
  68. @can_speak = true
  69. end
  70. end
  71.  
  72. class Chimpanzee < Primate
  73. end
  74.  
  75. Bird.new.fly
  76. puts Bird.new.can_fly
  77. Parrot.new.fly
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement