Pseudovariables

Table 4 shows Ruby’s pseudovariables. A pseudovariable is an object that looks like a variable, acts like a constant, and can’t be assigned a value. These are also listed in Table 1.

Table 4. Pseudovariables in Ruby

Pseudovariable

Description

false

Logical or Boolean false; instance of FalseClass.

nil

Empty, uninitialized, or invalid; always false, but not the same as zero; object of NilClass.

self

Current object (receiver invoked by a method).

true

Logical or Boolean true; instance of TrueClass.

_ _FILE_ _

Name of current source file.

_ _LINE_ _

Number of current line in the current source file.

Get Ruby Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.