Tutorial ↑

Why OptionParser? ↑

When a Ruby program executes, it captures its command-line arguments and options into variable ARGV. This simple program just prints its ARGV:

p ARGV

Execution, with arguments and options:

$ ruby argv.rb foo --bar --baz bat bam
["foo", "--bar", "--baz", "bat", "bam"]

The executing program is responsible for parsing and handling the command-line options.

OptionParser offers methods for parsing and handling those options.

With OptionParser, you can define options so that for each option:

The class also has method help, which displays automatically-generated help text.

Contents ↑