if var.nil?¶
ifの条件がvar.nil?のようになっていると、コンパイラはthen節ではvarがNil型だと判断して、elseではNil型以外の型だと判断します。
a = some_condition ? nil : 3
if a.nil?
# ここで a は Nil 型
else
# ここで a は Int32 型
end
ifの条件がvar.nil?のようになっていると、コンパイラはthen節ではvarがNil型だと判断して、elseではNil型以外の型だと判断します。
a = some_condition ? nil : 3
if a.nil?
# ここで a は Nil 型
else
# ここで a は Int32 型
end