Boolean Negation
The unary !
operator is used to negate a condition. Be sure to not mix this up with the not
operator which has different precedence than !
.
!true # => false
!false # => true
Depending on how you feel about using unless
, you may prefer negating a condition with !
.
if !book.valid?
render :new
end
See the Ruby docs ↗.