Ruby Language Reference

unless statement

Syntax

unless (conditional is false)
  execute code section 1
else
  execute code section 2
end

If the conditional is false, the unless executes code. If the conditional is true, code specified in the else clause is executed.

If the unless has an else section, for clarity, it is better to flip the conditionals, like this:

if (conditional is true)
  execute  code section 1
else
  execute code section 2
end

Unless in Statement Modifier

raining = false

p 'No umbrella required' unless raining

This prints:

No umbrella required


Sharing is Caring