All objects may be converted to booleans in Ruby

suggest change

Use the double negation syntax to check for truthiness of values. All values correspond to a boolean, irrespective of their type.

irb(main):001:0> !!1234
=> true
irb(main):002:0> !!"Hello, world!"
(irb):2: warning: string literal in condition
=> true
irb(main):003:0> !!true
=> true
irb(main):005:0> !!{a:'b'}
=> true

All values except nil and false are truthy.

irb(main):006:0> !!nil
=> false
irb(main):007:0> !!false
=> false

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents