全部OR
ならtrue
が来たら評価がとまって実行されない
def hoge
puts :hoge
false
end
def foo
puts :foo
true
end
def bar
puts :bar
true
end
unless hoge || foo || bar
puts :a
end
結果:
hoge
foo
全部AND
ならfalse
が来たら評価がとまって実行される
def hoge
puts :hoge
true
end
def foo
puts :foo
false
end
def bar
puts :bar
true
end
unless hoge && foo && bar
puts :a
end
結果:
hoge
foo
a
よくよく見ると評価がとまるのif
のときと同じか。。。
とはいえ、ややこしいので ベストプラクティスとしては、 unless
で&&
や||
を使ってはいけない。混乱しやすい。