Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

undef

Creating and inspecting undefined values.

undef.from

undef.from value -> Undefined

Returns an undefined value that carries value, for example a message that explains the error. The whole argument is wrapped, even a tuple.

err = undef.from "not found"
type err             # => "Undefined"
(undef.inspect err).val        # => "not found"

undef.inspect

undef.inspect u -> Namespace

Returns a namespace that describes the undefined value u. Its type member names the kind of error, and the other members depend on it:

typeMembersMeaning
UnaryOperationop, val, posoperation op failed on the operand val
BinaryOperationop, lhv, rhv, posoperation op failed on lhv and rhv
Terminationexpected, posthe closing bracket expected is missing
Tokentoken, posa token is in the wrong place
Nameposa name was expected
Valuevalcreated by undef.from

pos is the position of the error in the source, in bytes from the start of the expression; built-in functions report 0. Operands that are themselves undefined are described in the same way. If u is not undefined, the result is Undefined.

e = undef.inspect ([1] - 1)
e.type               # => "BinaryOperation"
e.op                 # => "subtraction"
(e.lhv, e.rhv)       # => ([1], 1)
(undef.inspect (text.size 1)).(op, val)  # => ("text.size", 1)