Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. class Person
  2.  
  3. attr_reader :name
  4. attr_accessor :bank_account
  5.  
  6. def initialize(name = "unknown")
  7. @name=name
  8. @bank_account = 25
  9. @happiness = 8
  10. @hygiene = 8
  11. end
  12.  
  13. def clean?
  14. if @hygiene > 7
  15. return true
  16. else
  17. return false
  18. end
  19. end
  20.  
  21. def happy?
  22. if @happiness > 7
  23. return true
  24. else
  25. return false
  26. end
  27. end
  28.  
  29. def get_paid(salary)
  30. @bank_account += salary
  31. return "all about the benjamins"
  32. end
  33.  
  34. def hygiene=(hygiene)
  35. if hygiene > 10
  36. @hygiene = 10
  37. elsif hygiene < 0
  38. @hygiene = 0
  39. else
  40. @hygiene = hygiene
  41. end
  42. end
  43.  
  44. def hygiene
  45. @hygiene
  46. end
  47.  
  48. def happiness=(happiness)
  49. if happiness > 10
  50. @happiness = 10
  51. elsif happiness < 0
  52. @happiness = 0
  53. else
  54. @happiness = happiness
  55. end
  56. end
  57.  
  58. def happiness
  59. @happiness
  60. end
  61.  
  62. def take_bath
  63. self.hygiene += 4
  64.  
  65. return "♪ Rub-a-dub just relaxing in the tub ♫"
  66. end
  67.  
  68. def work_out
  69. self.hygiene -= 3
  70. self.happiness += 2
  71. return "♪ another one bites the dust ♫"
  72. end
  73.  
  74. def call_friend(friend)
  75. self.happiness += 3
  76. friend.happiness += 3
  77. return "Hi #{friend.name}! It's #{self.name}"
  78. end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement