Appendix A. Ruby Reference

Reference material on Ruby is gathered in this appendix for your convenience. You will find information about the following: interpreter options, reserved words (keywords), operators, escape characters, predefined variables, global constants, regular expressions, String unpack directives, Array pack directives, flags and fields for sprintf, file tests from Kernel#test, time formatting directives, RDoc options, and Rake options.

Ruby Interpreter

Here is the syntax for the Ruby interpreter:

ruby [switches] [--] [program filename] [arguments]

Switches (or command-line options) include:

−0[octal]

Specify record separator (\0 if no argument)

-a

Set autosplit mode with -n or -p (splits $_ into $F)

-c

Check syntax only

-Cdirectory

cd to directory before executing your script

-d

Set debugging flags (set $DEBUG to true)

-e 'command'

Execute one line of script; several -e’s allowed; omit [program filename]

-Fpattern

split( ) pattern for autosplit (-a)

-i[extension]

Edit ARGV files in place (make backup if extension is supplied)

-Idirectory

Specify $LOAD_PATH directory (may be used more than once)

-Kkcode

Specify KANJI (Japanese) code-set

-l

Enable line-ending processing

-n

Assume 'while gets( ); ... end' loop around your script

-p

Assume loop similar to -n but print line similar to sed

-rlibrary

Require the library, before executing your script

-s

Enable some switch parsing for switches after script name

-S

Look for the script using a PATH environment variable

-T[level]

Turn on tainting checks

-v

Print ...

Get Learning Ruby now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.