We have seen that the if
condition works on true
and
false values.
In Ruby, nil is
like false.
In the example given above, can_vote
has nil value. This is why, Ruby
executed the else part of
the code.
Ruby treats both false and nil
similar to false and we call it falsy.
Opposite of falsy is truthy.
Ruby treats everything else as truthy.
It means any string or any number is truthy.
As we can see above,
Ruby treated s as truthy.
In summary, false
and
nil are falsy.
Everything else is truthy.