Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. module Flight
  2. def fly
  3. puts "I'm a parrot, I'm flying!"
  4. end
  5. end
  6.  
  7. class Animal
  8. attr_reader :name
  9. def initialize(name)
  10. @heart = 1
  11. @name = name
  12. end
  13. def heart
  14. @heart
  15. end
  16. end
  17.  
  18. class Mammal < Animal
  19. end
  20.  
  21. class Amphibian < Animal
  22. end
  23.  
  24. class Primate < Mammal
  25. attr_reader
  26. def initialize(name)
  27. super(name)
  28. @legs = 2
  29. @strength = 10
  30. end
  31. def legs
  32. @legs
  33. end
  34. def strength
  35. @strength
  36. end
  37. end
  38.  
  39. class Frog < Amphibian
  40. end
  41.  
  42. class Bat < Mammal
  43. end
  44.  
  45. class Bird < Animal
  46. end
  47.  
  48. class Parrot < Bird
  49. include Flight
  50.  
  51. end
  52.  
  53. class Chimpanzee < Primate
  54. def initialize(name)
  55. super(name)
  56. @hairy = "very"
  57. end
  58. end
  59. primate1 = Primate.new('Joe')
  60. chimp11 = Chimpanzee.new('Bob')
  61. puts "#{chimp11.name} has #{chimp11.heart} heart"
  62. puts "#{chimp11.name} has #{chimp11.legs} legs"
  63. puts "#{chimp11.name} has #{chimp11.strength}KG grip strength"
  64. puts primate1.inspect
  65. puts chimp11.inspect
  66. parrot1 = Parrot.new('Hyuk')
  67. puts parrot1.inspect
  68. parrot1.fly
  69. bat1 = Bat.new('yolo')
  70. puts bat1.inspect
  71. bat1.fly #Bat doesn't work because I did not include the module Flight in the Bat class or any of its superclasses
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement