Predefined Variables
Ruby’s predefined (built-in) variables affect the behavior of the entire program, so their use in libraries isn’t recommended. The values in most predefined variables can be accessed by alternative means.
$!The last exception object raised. The exception object can also be accessed using
=>inrescueclause.$@The
stack backtracefor the last exception raised. Thestack backtraceinformation can retrieved byException#backtracemethod of the last exception.$/The input record separator (newline by default).
gets,readline, etc., take their input record separator as optional argument.$\The output record separator (
nilby default).$,The output separator between the arguments to print and
Array#join(nilby default). You can specify separator explicitly toArray#join.$;The default separator for
split(nilby default). You can specify separator explicitly forString#split.$.The number of the last line read from the current input file. Equivalent to
ARGF.lineno.$<Synonym for
ARGF.$>Synonym for
$defout.$0The name of the current Ruby program being executed.
$$The
process.pidof the current Ruby program being executed.$?The exit status of the last process terminated.
$:Synonym for
$LOAD_PATH.$DEBUGTrue if the
-dor--debugcommand-line option is specified.$defoutThe destination output for
printandprintf($stdoutby default).$FThe variable that receives the output from
splitwhen-ais specified. This variable is set if the-acommand-line option is specified ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access