if var.nil?

If an if‘s condition is var.nil? then the type of var in the then branch is known by the compiler to be Nil, and to be known as non-Nil in the else branch:

  1. a = some_condition ? nil : 3
  2. if a.nil?
  3. # here a is Nil
  4. else
  5. # here a is Int32
  6. end