unless

An unless evaluates the then branch if its condition is falsey, and evaluates the else branch, if there’s any, otherwise. That is, it behaves in the opposite way of an if:

  1. unless some_condition
  2. expression_when_falsey
  3. else
  4. expression_when_truthy
  5. end
  6. # The above is the same as:
  7. if some_condition
  8. expression_when_truthy
  9. else
  10. expression_when_falsey
  11. end
  12. # Can also be written as a suffix
  13. close_door unless door_closed?