@@ -43,7 +43,6 @@ Contents:
4343 - {Handler Blocks}[#label-Handler+Blocks]
4444 - {Handler Procs}[#label-Handler+Procs]
4545 - {Handler Methods}[#label-Handler+Methods]
46- - {Terminators}[#label-Terminators]
4746
4847=== Option Names
4948
@@ -319,7 +318,7 @@ You can specify argument values in either of two ways:
319318===== Explicit Values in Array
320319
321320You can specify explicit argument values in an array of strings.
322- The argument value must be one of those strings.
321+ The argument value must be one of those strings, or an unambiguous abbreviation .
323322
324323File +explicit_array_values.rb+ defines options with explicit argument values.
325324
@@ -335,17 +334,21 @@ Executions:
335334 explicit_array_values.rb:9:in `<main>': missing argument: -x (OptionParser::MissingArgument)
336335 $ ruby explicit_array_values.rb -x foo
337336 ["-x", "foo"]
337+ $ ruby explicit_array_values.rb -x f
338+ ["-x", "foo"]
338339 $ ruby explicit_array_values.rb -x bar
339340 ["-x", "bar"]
341+ $ ruby explicit_array_values.rb -y ba
342+ explicit_array_values.rb:9:in `<main>': ambiguous argument: -y ba (OptionParser::AmbiguousArgument)
340343 $ ruby explicit_array_values.rb -x baz
341344 explicit_array_values.rb:9:in `<main>': invalid argument: -x baz (OptionParser::InvalidArgument)
342345
343346
344347===== Explicit Values in Hash
345348
346349You can specify explicit argument values in a hash with string keys.
347- The value passed must be one of those keys,
348- and the value yielded will be the value for that key.
350+ The value passed must be one of those keys, or an unambiguous abbreviation;
351+ the value yielded will be the value for that key.
349352
350353File +explicit_hash_values.rb+ defines options with explicit argument values.
351354
@@ -361,6 +364,8 @@ Executions:
361364 explicit_hash_values.rb:9:in `<main>': missing argument: -x (OptionParser::MissingArgument)
362365 $ ruby explicit_hash_values.rb -x foo
363366 ["-x", 0]
367+ $ ruby explicit_hash_values.rb -x f
368+ ["-x", 0]
364369 $ ruby explicit_hash_values.rb -x bar
365370 ["-x", 1]
366371 $ ruby explicit_hash_values.rb -x baz
@@ -371,6 +376,8 @@ Executions:
371376 ["-y", 2]
372377 $ ruby explicit_hash_values.rb -y bat
373378 ["-y", 3]
379+ $ ruby explicit_hash_values.rb -y ba
380+ explicit_hash_values.rb:9:in `<main>': ambiguous argument: -y ba (OptionParser::AmbiguousArgument)
374381 $ ruby explicit_hash_values.rb -y bam
375382 ["-y", nil]
376383
@@ -500,22 +507,3 @@ Executions:
500507 ["Handler method for -xxx called with value:", true]
501508 $ ruby method.rb --yyy FOO
502509 ["Handler method for -yyy called with value:", "FOO"]
503-
504- === Terminators
505-
506- And finally, the terminator parameter <tt>--</tt> tells the options parser
507- to ignore any options farther to the right.
508- This can be useful if there are options not meant for the current program.
509-
510- File +terminator.rb+ defines one option <tt>--my_option</tt>.
511-
512- :include: ruby/terminator.rb
513-
514- The first execution fails because <tt>--nosuch</tt> is not a defined option;
515- the second succeeds because <tt>--</tt> causes that option to be ignored:
516-
517- $ ruby terminator.rb --my_option FOO --other_option BAR
518- ["FOO", String]
519- terminator.rb:6:in `<main>': invalid option: --other_option (OptionParser::InvalidOption)
520- $ ruby terminator.rb --my_option FOO -- --other_option BAR
521- ["FOO", String]
0 commit comments