The double bang

In Ruby, you can simply negate an expression by using "!"

abc = 'abc'
!abc #=> false

Similarly,  

abc = 'abc'

!abc #=> false
!!abc #=> true

Ruby's double-bang negates the negated statement, which almost always will give you true.

a = 0
b = 1
c = true
d = false

!a #=> false
!!a #=> true
!b #=> false
!!b #=> true
!c #=> false
!!c #=> true
!d #=> true
!!d #=> false

So be careful using the double bang to test for truth. Better test with positive equality in your conditions over using the double bang.

Maricris Nonato

I turn tech ideas into websites using Ruby. I'm a budding Buddhist practitioner, passionate about health & fitness, and a cat fanatic!