Ruby Cheat Sheet
Explore key concepts, syntax, and usage examples for Ruby β perfect for quick reference.
Resource
Online Related
Array
File
String
Math
Integer
Numeric
Object
Hash
Regexp
IO
Methods
- ::binread
- ::binwrite
- ::copy_stream
- ::for_fd
- ::foreach
- ::new
- ::open
- ::pipe
- ::popen
- ::read
- ::readlines
- ::select
- ::sysopen
- ::try_convert
- ::write
- #<<
- #advise
- #autoclose=
- #autoclose?
- #binmode
- #binmode?
- #bytes
- #chars
- #close
- #close_on_exec=
- #close_on_exec?
- #close_read
- #close_write
- #closed?
- #codepoints
- #each
- #each_byte
- #each_char
- #each_codepoint
- #each_line
- #eof
- #eof?
- #external_encoding
- #fcntl
- #fdatasync
- #fileno
- #flush
- #fsync
- #getbyte
- #getc
- #gets
- #inspect
- #internal_encoding
- #ioctl
- #isatty
- #lineno
- #lineno=
- #lines
- #pid
- #pos
- #pos=
- #printf
- #putc
- #puts
- #read
- #read_nonblock
- #readbyte
- #readchar
- #readline
- #readlines
- #readpartial
- #reopen
- #rewind
- #seek
- #set_encoding
- #stat
- #sync
- #sync=
- #sysread
- #sysseek
- #syswrite
- #tell
- #to_i
- #to_io
- #tty?
- #ungetbyte
- #ungetc
- #write
- #write_nonblock
Time
ARGF
BasicObject
Bignum
Class
Complex
Encoding
Enumerator
Exception
Fiber
Float
Fixnum
Kernel
Method
Module
Proc
Process
Methods
- ::abort
- ::daemon
- ::detach
- ::egid
- ::egid=
- ::euid
- ::euid=
- ::exec
- ::exit
- ::exit!
- ::fork
- ::getpgid
- ::getpgrp
- ::getpriority
- ::getrlimit
- ::gid
- ::gid=
- ::groups
- ::groups=
- ::initgroups
- ::kill
- ::maxgroups
- ::maxgroups=
- ::pid
- ::ppid
- ::setpgid
- ::setpgrp
- ::setpriority
- ::setrlimit
- ::setsid
- ::spawn
- ::times
- ::uid
- ::uid=
- ::wait
- ::wait2
- ::waitall
- ::waitpid
- ::waitpid2
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.
- 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