Truthiness in Ruby

  • The way booleans are treated in most languages it’s not same in Ruby.
  • True and false are the only true booleans in Ruby.
  • That is all well and good but in our day to day dealings with Ruby we do not always come across true and false.We come across expressions which will be evaluated as true and false.

!! operator

  • This operator evaluates your expression into true or false.

!!7 = true

!!8 = true

!!0 = true (what? yeah ruby evaluates any number to true)

!!nil = false (always remember)

Like what you read? Give Shadeslayer a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.