Sha256: dc1a3c481eac16f2a54c3f701d6382a99ea7e232d214d03d36dc751d86b54aab
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 KB
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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
getopt-1.3.7 | examples/example_std.rb |