ESC
Type to search...
S
Soli Docs

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:

.to_s / .to_string

Convert to an empty string.

null.to_s      # ""
null.to_string # ""
.to_i / .to_int

Convert to zero.

null.to_i    # 0
null.to_int  # 0
.to_f / .to_float

Convert to zero float.

null.to_f      # 0.0
null.to_float  # 0.0
.to_a / .to_array

Convert to an empty array.

null.to_a      # []
null.to_array  # []

Introspection Methods

.class

Returns the type name as a string.

null.class   # "null"
.inspect

Returns a developer-friendly string representation.

null.inspect # "null"
.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
.nil?

Returns true (null is the only type where .nil? returns true).

null.nil?    # true
.blank? / .present?

Null is always blank and never present.

null.blank?    # true
null.present?  # false