Running Ruby

Test to see whether Ruby is running on your computer by typing the following at a shell or command prompt:

ruby --version

An affirmative response will look similar to this (this example is for version 1.8.6 running on Mac OS X):

ruby 1.8.6 (2007-03-13 patchlevel 0) [powerpc-darwin8.9.0]

You can install Ruby on any of the major platforms. For Ruby file archives and installation instructions, see http://www.ruby-lang.org/en/downloads.

Running the Ruby Interpreter

Usage:

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

Switches (or command-line options):

-0[octal]

Specify a record separator (\0 if no argument).

-a

Autosplit mode with -n or -p (splits $_ into $F).

-c

Check syntax only.

-Cdirectory

cd to directory before executing your script or program.

-d

Set debugging flags (set predefined variable $DEBUG to true).

-e 'command'

Execute one line of script. Several -es allowed. Omit [program filename].

-Fpattern

split( ) pattern for autosplit (-a).

-i[extension]

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

-Idirectory

Specify $LOAD_PATH (predefined variable) directory; may be used more than once.

-Kkcode

Specify the character set. See Table 16.

-l

Enable line-ending processing.

-n

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

-p

Assume loop like -n but print line also like 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 PATH environment variable.

-T[level]

Turn on tainting checks. ...

Get Ruby Pocket Reference 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.