unless¶
unless
は、条件が偽の場合に then ブランチを評価し、else ブランチ
がある場合はそれを評価します。そうでない場合は、if
とは逆の方法で動作します。
unless some_condition
expression_when_falsey
else
expression_when_truthy
end
# The above is the same as:
if some_condition
expression_when_truthy
else
expression_when_falsey
end
# Can also be written as a suffix
close_door unless door_closed?