Null nil
The absence of a value. Null provides safe conversion methods and introspection support.
About Null
# Null represents the absence of a value
let x = null
let typed: Null = null
# nil is an alias for null
let y = nil # same as null
print(y) # null
# Uninitialized variables
let z
print(z) # null
# Missing hash keys return null
let h = {"name": "Alice"}
print(h["age"]) # null
# Safe navigation to avoid errors on null
let user = null
print(user&.name) # null (no error)
Conversion Methods
Null can be safely converted to any primitive type with sensible defaults:
Introspection Methods
.is_a?(type_name)
Check if the value is of the given type. Supports "null" and "object".
null.is_a?("null") # true
null.is_a?("object") # true
null.is_a?("string") # false
.blank? / .present?
Null is always blank and never present.
null.blank? # true
null.present? # false