Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. class Pet
  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. def feed(food)
  10. puts "Mmmm, " + food + "!"
  11. @hungry = false
  12. end
  13. def hungry?
  14. if @hungry
  15. puts "I\'m hungry!"
  16. else
  17. puts "I'\m full!"
  18. end
  19. @hungry
  20. end
  21. end
  22.  
  23. class Cat < Pet
  24. def speak
  25. puts "Meow!"
  26. end
  27. end
  28.  
  29. class Dog < Pet
  30. def speak
  31. puts "Woof!"
  32. end
  33. end
  34.  
  35. kitty = Cat.new("grey","Persian")
  36. kitty.name = "Jack"
  37. puts kitty.name
  38. kitty.feed("fish")
  39. kitty.hungry?
  40. kitty.speak
  41.  
  42. puppy = Dog.new("black","Staffordshire Terrier")
  43. puppy.speak
  44. puts puppy.breed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement