This is because x =! 5
is being interpreted as x = (!5)
(!
has higer precedence than =
). In Ruby every object is true
except nil
and false
. 5
has truthy value which you are negating using the operator !
. So false
as result is being assigned to the local variable x
.
!
Called Logical NOT
Operator - is used to reverse the logical state of its operand. If a condition is true
, then Logical NOT
operator will make false
.