Skip to Content
Ruby in a Nutshell
book

Ruby in a Nutshell

by Yukihiro Matsumoto
November 2001
Intermediate to advanced
218 pages
6h 22m
English
O'Reilly Media, Inc.
Content preview from Ruby in a Nutshell

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 => in rescue clause.

$@

The stack backtrace for the last exception raised. The stack backtrace information can retrieved by Exception#backtrace method 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 (nil by default).

$,

The output separator between the arguments to print and Array#join (nil by default). You can specify separator explicitly to Array#join.

$;

The default separator for split (nil by default). You can specify separator explicitly for String#split.

$.

The number of the last line read from the current input file. Equivalent to ARGF.lineno.

$<

Synonym for ARGF.

$>

Synonym for $defout.

$0

The name of the current Ruby program being executed.

$$

The process.pid of the current Ruby program being executed.

$?

The exit status of the last process terminated.

$:

Synonym for $LOAD_PATH.

$DEBUG

True if the -d or --debug command-line option is specified.

$defout

The destination output for print and printf ($stdout by default).

$F

The variable that receives the output from split when -a is specified. This variable is set if the -a command-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

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Ruby by Example

Ruby by Example

Kevin C. Baird
Ruby Wizardry

Ruby Wizardry

Eric Weinstein
Ruby Best Practices

Ruby Best Practices

Gregory T Brown
Refactoring in Ruby

Refactoring in Ruby

William C. Wake, Kevin Rutherford

Publisher Resources

ISBN: 0596002149Errata Page