Advertisement
Guest User

Untitled

a guest
Jul 30th, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. $ pry
  2. >> class String
  3. | def to_bool
  4. | raise RuntimeError, 'Go fuck yourself' unless ['true', 'false'].include?(self)
  5. | self == 'true'
  6. | end
  7. | end
  8. :to_bool
  9. >> 'true'.to_bool
  10. true
  11. >> 'false'.to_bool
  12. false
  13. >> 'shit'.to_bool
  14. RuntimeError: Go fuck yourself
  15. from (pry):3:in `to_bool'
  16. >> # or more simplistic way
  17. >> le_string = 'true'
  18. "true"
  19. >> (le_string == 'true')
  20. true
  21. >> le_string = 'false'
  22. "false"
  23. >> (le_string == 'true')
  24. false
  25. >>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement