Guest User

Untitled

a guest
May 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. class Cat
  2. attr_reader :color, :breed
  3. attr_accessor :name
  4. def initialize(color, breed)
  5. @color = color
  6. @breed = breed
  7. @hungry = true
  8. end
  9.  
  10. def feed(food)
  11. puts "Mmmm, " + food + "!"
  12. @hungry = false
  13. end
  14.  
  15. def hungry?
  16. if @hungry
  17. puts "I'm hungry!"
  18. else
  19. puts "I'm full!"
  20. end
  21. @hungry
  22. end
  23.  
  24. def speak
  25. puts "Meow!"
  26. end
  27.  
  28. end
  29.  
  30. kitty = Cat.new("grey", "Persian")
  31. puts "Let's inspect our new cat:"
  32. puts kitty.inspect
  33. puts "What class does our new cat belong to?"
  34. puts kitty.class
  35. puts "Is our new cat an object?"
  36. puts kitty.is_a?(Object)
  37. puts "What color is our cat?"
  38. puts kitty.color
  39. puts "Let's give our cat a name"
  40. kitty.name = "Betsy"
  41. puts kitty.name
  42. puts "Is our cat hungry now?"
  43. kitty.hungry?
  44. puts "Let's feed our cat"
  45. kitty.feed("tuna")
  46. puts "Is our cat hungry now?"
  47. kitty.hungry?
  48. puts "Our cat can make noise"
  49. kitty.speak
Add Comment
Please, Sign In to add comment