Guest User

Untitled

a guest
May 27th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 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 "mmm, " + 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. end
  28.  
  29. kitty = Cat.new("grey", "persian")
  30.  
  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 kitty.is_a?(Object)
  36.  
  37. puts "Let's give our new cat a name"
  38. kitty.name = "Betsy"
  39. puts kitty.name
  40.  
  41. puts "What color is our cat?"
  42. puts kitty.color
  43.  
  44. puts "is our cat hungry now?"
  45. kitty.hungry?
  46. puts "lets feed our cat"
  47. kitty.feed("tuna")
  48. puts "is our kitty hungry now?"
  49. kitty.hungry?
  50.  
  51. puts "our kitten can speak"
  52. kitty.speak
Add Comment
Please, Sign In to add comment