Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. module Flight
  2. attr_accessor(:flight_speed)
  3. def fly
  4. puts "I am a #{self.class}, I am flying at #{flight_speed} miles per hour"
  5. end
  6. end
  7.  
  8. class Animal
  9. attr_accessor(:brain)
  10. def initialize(brain)
  11. @brain = brain
  12. end
  13. end
  14.  
  15. class Mammal < Animal
  16. def initialize(brain)
  17. super(brain)
  18. end
  19.  
  20. def live_birth
  21. puts "I have live birth"
  22. end
  23. end
  24.  
  25. class Amphibian < Animal
  26. def initialize(brain)
  27. super(brain)
  28. end
  29. def lay_egg
  30. puts "I can lay an egg"
  31. end
  32. end
  33.  
  34. class Primate < Mammal
  35. def initialize(brain)
  36. super(brain)
  37. @legs = 2
  38. end
  39.  
  40. def land_dweller
  41. puts "I like the land"
  42. end
  43. end
  44.  
  45. class Frog < Amphibian
  46. def initialize(brain)
  47. super(brain)
  48. end
  49. end
  50.  
  51. class Chimpanzee < Primate
  52. def initialize(brain)
  53. super(brain)
  54. end
  55.  
  56. def tools
  57. puts "I can use tools"
  58. end
  59. end
  60.  
  61. class Bat < Animal
  62. include Flight
  63. def initialize(brain)
  64. super(brain)
  65. end
  66. end
  67.  
  68. class Parrot < Animal
  69. include Flight
  70. def initialize(brain)
  71. super(brain)
  72. end
  73.  
  74. end
  75.  
  76.  
  77. bat1 = Bat.new(true)
  78. bat1.flight_speed = 2
  79. bat1.fly
  80.  
  81. parrot1 = Parrot.new(true)
  82. parrot1.flight_speed = 7
  83. parrot1.fly
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement