Guest User

Untitled

a guest
Dec 14th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. class Drink
  2. def sip
  3. puts "You drank with caution"
  4. end
  5. end
  6.  
  7. class Coffee < Drink
  8. def method_missing(method_name, *args, &block)
  9. if method_name == :gulp
  10. puts "Please don't gulp your coffee!"
  11. sip
  12. else
  13. super
  14. # this will do the normal thing of raising an exception that the method wasn't found
  15. end
  16. end
  17. end
  18.  
  19. class Water < Drink
  20. def gulp
  21. puts "You drank the water with reckless abandon!"
  22. end
  23. end
Add Comment
Please, Sign In to add comment