Ruby Cheat Sheet

Explore key concepts, syntax, and usage examples for Ruby β€” perfect for quick reference.

Resource
Array
File
String
Math
Integer
Numeric
Object
Hash
Regexp
Time
ARGF
BasicObject
Bignum
Class
Complex
Exception
Fiber
Float
Fixnum
Kernel
Method
Module
Proc
Random
Range
Rational
Symbol
Thread
Pre-defined
Variables
  • $!
    πŸ’‘ The exception information message set by β€˜raise’.
  • $@
    πŸ’‘ Array of backtrace of the last exception thrown.
  • $&
    πŸ’‘ The string matched by the last successful pattern match in this scope.
  • $`
    πŸ’‘ The string to the left of the last successful match.
  • $'
    πŸ’‘ The string to the right of the last successful match.
  • $+
    πŸ’‘ The last bracket matched by the last successful match.
  • $1
    πŸ’‘ The Nth group of the last successful match. May be > 1.
  • $~
    πŸ’‘ The information about the last match in the current scope.
  • $=
    πŸ’‘ The flag for case insensitive, nil by default.
  • $/
    πŸ’‘ The input record separator, newline by default.
  • $\
    πŸ’‘ The output record separator for the print and IO#write. Default is nil.
  • $,
    πŸ’‘ The output field separator for the print and Array#join.
  • $;
    πŸ’‘ The default separator for String#split.
  • $.
    πŸ’‘ The current input line number of the last file that was read.
  • $<
    πŸ’‘ The virtual concatenation file of the files given on command line.
  • $>
    πŸ’‘ The default output for print, printf. $stdout by default.
  • $_
    πŸ’‘ The last input line of string by gets or readline.
  • $0
    πŸ’‘ Contains the name of the script being executed. May be assignable.
  • $*
    πŸ’‘ Command line arguments given for the script sans args.
  • $$
    πŸ’‘ The process number of the Ruby running this script.
  • $?
    πŸ’‘ The status of the last executed child process.
  • $:
    πŸ’‘ Load path for scripts and binary modules by load or require.
  • $"
    πŸ’‘ The array contains the module names loaded by require.
  • $DEBUG
    πŸ’‘ The status of the -d switch.
  • $FILENAME
    πŸ’‘ Current input file from $<. Same as $<.filename.
  • $LOAD_PATH
    πŸ’‘ The alias to the $:.
  • $stderr
    πŸ’‘ The current standard error output.
  • $stdin
    πŸ’‘ The current standard input.
  • $stdout
    πŸ’‘ The current standard output.
  • $VERBOSE
    πŸ’‘ The verbose flag, which is set by the -v switch.
  • $-0
    πŸ’‘ The alias to $/
  • $-a
    πŸ’‘ True if option -a is set. Read-only variable.
  • $-d
    πŸ’‘ The alias to $DEBUG.
  • $-F
    πŸ’‘ The alias to $;.
  • $-i
    πŸ’‘ In in-place-edit mode, this variable holds the extention, otherwise nil.
  • $-I
    πŸ’‘ The alias to $:.
  • $-l
    πŸ’‘ True if option -l is set. Read-only variable.
  • $-p
    πŸ’‘ True if option -p is set. Read-only variable.
  • $-v
    πŸ’‘ The alias to $VERBOSE.
Global Constant
  • TRUE
    πŸ’‘ The typical true value.
  • FALSE
    πŸ’‘ The false itself.
  • NIL
    πŸ’‘ The nil itself.
  • STDIN
    πŸ’‘ The standard input. The default value for $stdin.
  • STDOUT
    πŸ’‘ The standard output. The default value for $stdout.
  • STDERR
    πŸ’‘ The standard error output. The default value for $stderr.
  • ENV
    πŸ’‘ The hash contains current environment variables.
  • ARGF
    πŸ’‘ The alias to the $<.
  • ARGV
    πŸ’‘ The alias to the $*.
  • DATA
    πŸ’‘ The file object of the script, pointing just after __END__.
  • RUBY_VERSION
    πŸ’‘ The ruby version string (VERSION was depricated).
  • RUBY_RELEASE_DATE
    πŸ’‘ The relase date string.
  • RUBY_PLATFORM
    πŸ’‘ The platform identifier