The Pug Automatic

The !!! operator

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.

Even if you do accidentally leave it in, someone's bound to spot it in review. You could even prevent committing it altogether by technical means (1, 2).

Other name suggestions were "the mad hype operator" from Mike McDonald or "tri-not" ("the Yoda operator") from Christian Schlensker.

By any name, it's pretty sweet.