Pre-Defined Global VariablesΒΆ ↑

Some of the pre-defined global variables have synonyms that are available via module Engish. For each of those, the English synonym is given.

To use the module:

require 'English'

ExceptionsΒΆ ↑

$! (Exception)ΒΆ ↑

Contains the Exception object set by Kernel#raise:

begin
  raise RuntimeError.new('Boo!')
rescue RuntimeError
  p $!
end

Output:

#<RuntimeError: Boo!>

English - $ERROR_INFO

$@ (Backtrace)ΒΆ ↑

Same as $!.backtrace; returns an array of backtrace positions:

begin
  raise RuntimeError.new('Boo!')
rescue RuntimeError
  pp $@.take(4)
end

Output:

["(irb):338:in `<top (required)>'",
 "/snap/ruby/317/lib/ruby/3.2.0/irb/workspace.rb:119:in `eval'",
 "/snap/ruby/317/lib/ruby/3.2.0/irb/workspace.rb:119:in `evaluate'",
 "/snap/ruby/317/lib/ruby/3.2.0/irb/context.rb:502:in `evaluate'"]

English - $ERROR_POSITION.

Pattern MatchingΒΆ ↑

These global variables store information about the most recent successful match in the current scope.

For details and examples, see Regexp Global Variables.

$~ (MatchData)ΒΆ ↑

MatchData object created from the match; thread-local and frame-local.

English - $LAST_MATCH_INFO.

$& (Matched Substring)ΒΆ ↑

The matched string.

English - $MATCH.

$` (Pre-Match Substring)ΒΆ ↑

The string to the left of the match.

English - $PREMATCH.

$' (Post-Match Substring)ΒΆ ↑

The string to the right of the match.

English - $POSTMATCH.

$+ (Last Matched Group)ΒΆ ↑

The last group matched.

English - $LAST_PAREN_MATCH.

$1, $2, Etc. (Matched Group)ΒΆ ↑

For $n the nth group of the match.

No English.

SeparatorsΒΆ ↑

$/ (Input Record Separator)ΒΆ ↑

An input record separator, initially newline.

English - $INPUT_RECORD_SEPARATOR, $RS.

Aliased as $-0.

$; (Input Field Separator)ΒΆ ↑

An input field separator, initially nil.

English - $FIELD_SEPARATOR, $FS.

Aliased as $-F.

$\ (Output Record Separator)ΒΆ ↑

An output record separator, initially nil.

English - $OUTPUT_RECORD_SEPARATOR, $ORS.

StreamsΒΆ ↑

$stdin (Standard Input)ΒΆ ↑

The current standard input stream; initially:

$stdin # => #<IO:<STDIN>>

$stdout (Standard Output)ΒΆ ↑

The current standard output stream; initially:

$stdout # => #<IO:<STDOUT>>

$stderr (Standard Error)ΒΆ ↑

The current standard error stream; initially:

$stderr # => #<IO:<STDERR>>

$< (ARGF or $stdin)ΒΆ ↑

Points to stream ARGF if not empty, else to stream $stdin; read-only.

English - $DEFAULT_INPUT.

$> (Default Standard Output)ΒΆ ↑

An output stream, initially $stdout.

English - <tt>$DEFAULT_OUTPUT

$. (Input Position)ΒΆ ↑

The input position (line number) in the most recently read stream.

English - $INPUT_LINE_NUMBER, $NR

$_ (Last Read Line)ΒΆ ↑

The line (string) from the most recently read stream.

English - $LAST_READ_LINE.

ProcessesΒΆ ↑

$0ΒΆ ↑

Initially, contains the name of the script being executed; may be reassigned.

$* (ARGV)ΒΆ ↑

Points to ARGV.

English - $ARGV.

$$ (Process ID)ΒΆ ↑

The process ID of the current process. Same as Process.pid.

English - $PROCESS_ID, $PID.

$? (Child Status)ΒΆ ↑

Initially nil, otherwise the Process::Status object created for the most-recently exited child process; thread-local.

English - $CHILD_STATUS.

$LOAD_PATH (Load Path)ΒΆ ↑

Contains the array of paths to be searched by Kernel#load and Kernel#require.

Singleton method $LOAD_PATH.resolve_feature_path(feature) returns:

Examples:

$LOAD_PATH.resolve_feature_path('timeout')
# => [:rb, "/snap/ruby/317/lib/ruby/3.2.0/timeout.rb"]
$LOAD_PATH.resolve_feature_path('date_core')
# => [:so, "/snap/ruby/317/lib/ruby/3.2.0/x86_64-linux/date_core.so"]
$LOAD_PATH.resolve_feature_path('foo')
# => nil

Aliased as $: and $-I.

$LOADED_FEATURESΒΆ ↑

Contains an array of the paths to the loaded files:

$LOADED_FEATURES.take(10)
# =>
["enumerator.so",
 "thread.rb",
 "fiber.so",
 "rational.so",
 "complex.so",
 "ruby2_keywords.rb",
 "/snap/ruby/317/lib/ruby/3.2.0/x86_64-linux/enc/encdb.so",
 "/snap/ruby/317/lib/ruby/3.2.0/x86_64-linux/enc/trans/transdb.so",
 "/snap/ruby/317/lib/ruby/3.2.0/x86_64-linux/rbconfig.rb",
 "/snap/ruby/317/lib/ruby/3.2.0/rubygems/compatibility.rb"]

Aliased as $".

DebuggingΒΆ ↑

$FILENAMEΒΆ ↑

The value returned by method ARGF.filename.

$DEBUGΒΆ ↑

Initially true if command-line option -d or --debug is given, otherwise initially false; may be set to either value in the running program.

When true, prints each raised exception to $stderr.

Aliased as $-d.

$VERBOSEΒΆ ↑

Initially true if command-line option -v or -w is given, otherwise initially false; may be set to either value, or to nil, in the running program.

When true, enables Ruby warnings.

When nil, disables warnings, including those from Kernel#warn.

Aliased as $-v and $-w.

Other VariablesΒΆ ↑

$-aΒΆ ↑

Whether command-line option -a was given; read-only.

$-iΒΆ ↑

Contains the extension given with command-line option -i, or nil if none.

An alias of ARGF.inplace_mode.

$-lΒΆ ↑

Whether command-line option -l was set; read-only.

$-pΒΆ ↑

Whether command-line option -p was given; read-only.

DeprecatedΒΆ ↑

$=ΒΆ ↑

$,ΒΆ ↑

Pre-Defined Global ConstantsΒΆ ↑

StreamsΒΆ ↑

STDINΒΆ ↑

The standard input stream (the default value for $stdin):

STDIN # => #<IO:<STDIN>>

STDOUTΒΆ ↑

The standard output stream (the default value for $stdout):

STDOUT # => #<IO:<STDOUT>>

STDERRΒΆ ↑

The standard error stream (the default value for $stderr):

STDERR # => #<IO:<STDERR>>

EnvironmentΒΆ ↑

ENVΒΆ ↑

A hash of the contains current environment variables names and values:

ENV.take(5)
# =>
[["COLORTERM", "truecolor"],
 ["DBUS_SESSION_BUS_ADDRESS", "unix:path=/run/user/1000/bus"],
 ["DESKTOP_SESSION", "ubuntu"],
 ["DISPLAY", ":0"],
 ["GDMSESSION", "ubuntu"]]

ARGFΒΆ ↑

The virtual concatenation of the files given on the command line, or from $stdin if no files were given, "-" is given, or after all files have been read.

ARGVΒΆ ↑

An array of the given command-line arguments.

TOPLEVEL_BINDINGΒΆ ↑

The Binding of the top level scope:

TOPLEVEL_BINDING # => #<Binding:0x00007f58da0da7c0>

RUBY_VERSIONΒΆ ↑

The Ruby version:

RUBY_VERSION # => "3.2.2"

RUBY_RELEASE_DATEΒΆ ↑

The release date string:

RUBY_RELEASE_DATE # => "2023-03-30"

RUBY_PLATFORMΒΆ ↑

The platform identifier:

RUBY_PLATFORM # => "x86_64-linux"

RUBY_PATCHLEVELΒΆ ↑

The integer patch level for this Ruby:

RUBY_PATCHLEVEL # => 53

For a development build the patch level will be -1.

RUBY_REVISIONΒΆ ↑

The git commit hash for this Ruby:

RUBY_REVISION # => "e51014f9c05aa65cbf203442d37fef7c12390015"

The copyright string:

RUBY_COPYRIGHT
# => "ruby - Copyright (C) 1993-2023 Yukihiro Matsumoto"

RUBY_ENGINEΒΆ ↑

The name of the Ruby implementation:

RUBY_ENGINE # => "ruby"

RUBY_ENGINE_VERSIONΒΆ ↑

The version of the Ruby implementation:

RUBY_ENGINE_VERSION # => "3.2.2"

RUBY_DESCRIPTIONΒΆ ↑

The description of the Ruby implementation:

RUBY_DESCRIPTION
# => "ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]"

Embedded DataΒΆ ↑

DATAΒΆ ↑

Defined if and only if the program has this line:

__END__

When defined, DATA is a File object containing the lines following the __END__, positioned at the first of those lines:

p DATA
DATA.each_line { |line| p line }
__END__

Output:

#<File:t.rb>
"Foo\n"
"Bar\n"
"Baz\n"