Class Getopt::Std
In: lib/getopt/std.rb
Parent: Object

The Getopt::Std class serves as a base class for the getopts method.

Methods

getopts  

Classes and Modules

Class Getopt::Std::Error

Constants

VERSION = '1.4.1'   The version of the getopt library

Public Class methods

Processes single character command line options with option clustering. This information is parsed from ARGV and returned as a hash, with the switch (minus the "-") as the key. The value for that key is either true/false (boolean switches) or the argument that was passed to the switch.

Characters followed by a ":" require an argument. The rest are considered boolean switches. If a switch that accepts an argument appears more than once, the value for that key becomes an array of values.

Example:

 # Look for -o with argument, and -I and -D boolean arguments
 opt = Getopt::Std.getopts("o:ID")

 if opt["I"]
   # Do something if -I passed
 end

 if opt["D"]
    # Do something if -D passed
 end

 if opt["o"]
    case opt["o"]
       # Do something
    end
 end

[Validate]