A command-line argument supplies the Ruby interpreter with a program filename or a switch that changes its behavior or tells it to perform an action. Multiple switches can be combined when starting Ruby. section 1.4.1
Common arguments support checking, diagnostics, and small scripts:
- `-c` checks a file's syntax without executing it, while `-w` enables additional warnings. section 1.4.1
- `-e` executes Ruby code supplied in quotation marks, making short scripts possible without creating a file. section 1.4.1
- `-v` or `--version` displays Ruby version information; `-h` displays interpreter switch help. section 1.4.1
Run a one-line Ruby program
`ruby -e 'puts "David A. Black".reverse'` prints `kcalB .A divaD`. The quoted text is treated as the Ruby program rather than as a filename. section 1.4.1
Table 1.6 Commonly used Ruby command-line switches
| Switch |
Description |
Example of usage |
|---|---|---|
|
|
Checks the syntax of a program file without executing the program |
|
|
|
Gives warning messages during program execution |
|
|
|
Executes the code provided in quotation marks on the command line |
|
|
|
Line mode: prints a newline after every line of output |
|
|
|
Requires the named feature |
|
|
|
Shows Ruby version information and executes the program in verbose mode |
|
|
|
Shows Ruby version information |
|
|
|
Shows information about all command-line switches for the interpreter |
|
Browse the switch table for compact descriptions and usage examples covering syntax checks, warnings, inline execution, line mode, requiring features, version information, and help. section 1.4.1













