examples/example_std.rb in getopt-1.3.7 vs examples/example_std.rb in getopt-1.3.8

- old
+ new

@@ -1,38 +1,38 @@ -#################################################### -# 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. +#################################################### +# 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.