除非¶
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?