Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ pry
- >> class String
- | def to_bool
- | raise RuntimeError, 'Go fuck yourself' unless ['true', 'false'].include?(self)
- | self == 'true'
- | end
- | end
- :to_bool
- >> 'true'.to_bool
- true
- >> 'false'.to_bool
- false
- >> 'shit'.to_bool
- RuntimeError: Go fuck yourself
- from (pry):3:in `to_bool'
- >> # or more simplistic way
- >> le_string = 'true'
- "true"
- >> (le_string == 'true')
- true
- >> le_string = 'false'
- "false"
- >> (le_string == 'true')
- false
- >>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement