Advertisement
Guest User

Untitled

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