Sha256: 13401e560a23c482e3041f90feaaf387a70c12ca50443c76a9f0f3203d15bed5

Contents?: true

Size: 1018 Bytes

Versions: 4

Compression:

Stored size: 1018 Bytes

Contents

####################################################
# example_std.rb
#
# Some samples of how to use the Getopt::Std class.
#####################################################
base = File.basename(Dir.pwd)

if base == "examples" || base =~ /getopt/
   Dir.chdir("..") if base == "examples"
   $LOAD_PATH.unshift(Dir.pwd + "/lib")
   Dir.chdir("examples") rescue nil
end

require "getopt/std"
include Getopt

# Try passing different switches to this script to see what happens
opts = Std.getopts("o:ID")
p opts

# User passes "-o hello -I"
# Result: {"o" => "hello", "I" => true}

# User passes "-I -D"
# Result: {"I" => true, "D" => true}

# User passes nothing
# Result: {}

# User passes "-o hello -o world -I"
# Result: {"I" => true, "o" => ["hello", "world"]}

# User passes "-o -I"
# Result: Getopt::StdError, because -o requires an argument (and does not
#    accept -I as an argument, since it is a valid switch)

# User passes "-I -X"
# Result: Getopt::StdError, because -X was not listed as a valid switch.

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
getopt-1.4.1 examples/example_std.rb
getopt-1.4.0 examples/example_std.rb
getopt-1.3.9 examples/example_std.rb
getopt-1.3.8 examples/example_std.rb