Written January 9, 2015. Tagged Ruby.
A quick tip, based on a comment I wrote in the Ruby Rogues Parley "Operator nicknames" thread (paid membership) a while back and just stumbled across again.
I'm sure you've used
! in Ruby – it means "not":
!true # => false
You might have used
!! to coerce a truthy or falsy value into a bona fide boolean:
!!nil # => false
I sometimes use
It's just three of the
! operator in a row. It flips, flops and then flips back again, so it's really the same as a single one:
!!!true # => false
In that forum thread, I called it the "temporarily reverse the value of this bool to try something out, but it should stand out enough that I don't accidentally leave it in" operator. And that's what I use it for.
By any name, it's pretty sweet.