ÿØÿà JFIF    ÿÛ „  ( %!1!%)+//.383,7(-.+  -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ     ÿÄ J    ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ   ÿÄ *  !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú "SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5 ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e ríV ?> ......................................... ............................................................................. ÿØÿà JFIF    ÿÛ „  ( %!1!%)+//.383,7(-.+  -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ     ÿÄ J    ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ   ÿÄ *  !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú "SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5 ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e ríV ?> ......................................... ............................................................................. ???????????????????????????????????? ???????????????????????????????????? ÿØÿà JFIF    ÿÛ „  ( %!1!%)+//.383,7(-.+  -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ     ÿÄ J    ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ   ÿÄ *  !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú "SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5 ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e ríV ?> ......................................... ............................................................................. ÿØÿà JFIF    ÿÛ „  ( %!1!%)+//.383,7(-.+  -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ     ÿÄ J    ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ   ÿÄ *  !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú "SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5 ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e ríV ?> ......................................... ............................................................................. ???????????????????????????????????? ???????????????????????????????????? U:RDoc::TopLevel[ iI" optparse/option_params.rdoc:ETcRDoc::Parser::Simpleo:RDoc::Markup::Document: @parts[S:RDoc::Markup::Heading: leveli: textI"Parameters for New Options;To:RDoc::Markup::BlankLineo:RDoc::Markup::Paragraph;[I"/Option-creating methods in +OptionParser+ ;TI"Baccept arguments that determine the behavior of a new option:;T@ o:RDoc::Markup::List: @type: BULLET: @items[ o:RDoc::Markup::ListItem: @label0;[o; ;[I"OptionParser#on;To;;0;[o; ;[I"OptionParser#on_head;To;;0;[o; ;[I"OptionParser#on_tail;To;;0;[o; ;[I"OptionParser#define;To;;0;[o; ;[I"OptionParser#define_head;To;;0;[o; ;[I"OptionParser#define_tail;To;;0;[o; ;[I"OptionParser#make_switch;T@ o; ;[I"(The code examples on this page use:;T@ o;;;;[o;;0;[o; ;[I"(OptionParser#on, to define options.;To;;0;[o; ;[I"4OptionParser#parse!, to parse the command line.;To;;0;[o; ;[I"ABuilt-in option --help, to display defined options.;T@ o; ;[I"Contents:;T@ o;;;;[ o;;0;[o; ;[I"({Option Names}[#label-Option+Names];To;;;;[o;;0;[o; ;[I"&{Short Names}[#label-Short+Names];To;;;;[ o;;0;[o; ;[I"4{Simple Short Names}[#label-Simple+Short+Names];To;;0;[o; ;[I"V{Short Names with Required Arguments}[#label-Short+Names+with+Required+Arguments];To;;0;[o; ;[I"V{Short Names with Optional Arguments}[#label-Short+Names+with+Optional+Arguments];To;;0;[o; ;[I"<{Short Names from Range}[#label-Short+Names+from+Range];To;;0;[o; ;[I"${Long Names}[#label-Long+Names];To;;;;[ o;;0;[o; ;[I"2{Simple Long Names}[#label-Simple+Long+Names];To;;0;[o; ;[I"T{Long Names with Required Arguments}[#label-Long+Names+with+Required+Arguments];To;;0;[o; ;[I"T{Long Names with Optional Arguments}[#label-Long+Names+with+Optional+Arguments];To;;0;[o; ;[I"@{Long Names with Negation}[#label-Long+Names+with+Negation];To;;0;[o; ;[I"&{Mixed Names}[#label-Mixed+Names];To;;0;[o; ;[I"0{Argument Strings}[#label-Argument+Strings];To;;0;[o; ;[I".{Argument Values}[#label-Argument+Values];To;;;;[o;;0;[o; ;[I"@{Explicit Argument Values}[#label-Explicit+Argument+Values];To;;;;[o;;0;[o; ;[I"@{Explicit Values in Array}[#label-Explicit+Values+in+Array];To;;0;[o; ;[I">{Explicit Values in Hash}[#label-Explicit+Values+in+Hash];To;;0;[o; ;[I">{Argument Value Patterns}[#label-Argument+Value+Patterns];To;;0;[o; ;[I"6{Argument Converters}[#label-Argument+Converters];To;;0;[o; ;[I"({Descriptions}[#label-Descriptions];To;;0;[o; ;[I".{Option Handlers}[#label-Option+Handlers];To;;;;[o;;0;[o; ;[I",{Handler Blocks}[#label-Handler+Blocks];To;;0;[o; ;[I"*{Handler Procs}[#label-Handler+Procs];To;;0;[o; ;[I".{Handler Methods}[#label-Handler+Methods];T@ S; ; i; I"Option Names;T@ o; ;[I")There are two kinds of option names:;T@ o;;;;[o;;0;[o; ;[I"MShort option name, consisting of a single hyphen and a single character.;To;;0;[o; ;[I"LLong option name, consisting of two hyphens and one or more characters.;T@ S; ; i ; I"Short Names;T@ S; ; i ; I"Simple Short Names;T@ o; ;[I"0File +short_simple.rb+ defines two options:;T@ o;;;;[o;;0;[o; ;[I"%One with short name -x.;To;;0;[o; ;[I"UThe other with two short names, in effect, aliases, -1 and -%.;T@ o:RDoc::Markup::Verbatim;[I"require 'optparse' ;TI"parser = OptionParser.new ;TI"2parser.on('-x', 'One short name') do |value| ;TI" p ['-x', value] ;TI" end ;TI"Cparser.on('-1', '-%', 'Two short names (aliases)') do |value| ;TI" p ['-1 or -%', value] ;TI" end ;TI"parser.parse! ;T: @format0o; ;[I"Executions:;T@ o;;[I"#$ ruby short_simple.rb --help ;TI"#Usage: short_simple [options] ;TI"9 -x One short name ;TI"D -1, -% Two short names (aliases) ;TI"$ ruby short_simple.rb -x ;TI"["-x", true] ;TI"%$ ruby short_simple.rb -1 -x -% ;TI"["-1 or -%", true] ;TI"["-x", true] ;TI"["-1 or -%", true] ;T;0S; ; i ; I"(Short Names with Required Arguments;T@ o; ;[I";A short name followed (no whitespace) by a dummy word ;TI"1defines an option that requires an argument.;T@ o; ;[I"-x ;TI"that requires an argument.;T@ o;;[ I"require 'optparse' ;TI"parser = OptionParser.new ;TI"Hparser.on('-xXXX', 'Short name with required argument') do |value| ;TI" p ['-x', value] ;TI" end ;TI"parser.parse! ;T;0o; ;[I"Executions:;T@ o;;[ I"%$ ruby short_required.rb --help ;TI"%Usage: short_required [options] ;TI"L -xXXX Short name with required argument ;TI"!$ ruby short_required.rb -x ;TI"[short_required.rb:6:in `
': missing argument: -x (OptionParser::MissingArgument) ;TI"%$ ruby short_required.rb -x FOO ;TI"["-x", "FOO"] ;T;0S; ; i ; I"(Short Names with Optional Arguments;T@ o; ;[I"PA short name followed (with whitespace) by a dummy word in square brackets ;TI"8defines an option that allows an optional argument.;T@ o; ;[I"-x ;TI"&that allows an optional argument.;T@ o;;[ I"require 'optparse' ;TI"parser = OptionParser.new ;TI"Kparser.on('-x [XXX]', 'Short name with optional argument') do |value| ;TI" p ['-x', value] ;TI" end ;TI"parser.parse! ;T;0o; ;[I"Executions:;T@ o;;[ I"%$ ruby short_optional.rb --help ;TI"%Usage: short_optional [options] ;TI"L -x [XXX] Short name with optional argument ;TI"!$ ruby short_optional.rb -x ;TI"["-x", nil] ;TI"%$ ruby short_optional.rb -x FOO ;TI"["-x", "FOO"] ;T;0S; ; i ; I"Short Names from Range;T@ o; ;[I"8You can define an option with multiple short names ;TI"'taken from a range of characters. ;TI"EThe parser yields both the actual character cited and the value.;T@ o; ;[I">File +short_range.rb+ defines an option with short names ;TI"@for all printable characters from ! to ~:;T@ o;;[ I"require 'optparse' ;TI"parser = OptionParser.new ;TI"Oparser.on('-[!-~]', 'Short names in (very large) range') do |name, value| ;TI" p ['!-~', name, value] ;TI" end ;TI"parser.parse! ;T;0o; ;[I"Executions:;T@ o;;[I""$ ruby short_range.rb --help ;TI""Usage: short_range [options] ;TI"L -[!-~] Short names in (very large) range ;TI"$ ruby short_range.rb -! ;TI"["!-~", "!", nil] ;TI"$ ruby short_range.rb -! ;TI"["!-~", "!", nil] ;TI"$ ruby short_range.rb -A ;TI"["!-~", "A", nil] ;TI"$ ruby short_range.rb -z ;TI"["!-~", "z", nil] ;T;0S; ; i ; I"Long Names;T@ S; ; i ; I"Simple Long Names;T@ o; ;[I"/File +long_simple.rb+ defines two options:;T@ o;;;;[o;;0;[o; ;[I"&One with long name -xxx.;To;;0;[ o; ;[I"8The other with two long names, in effect, aliases, ;TI"'--y1% and --z2#.;T@ o; ;[I"require 'optparse' ;TI"parser = OptionParser.new ;TI"3parser.on('--xxx', 'One long name') do |value|;To;;[I"p ['--xxx', value] ;T;0o; ;[I" end ;TI"Gparser.on('--y1%', '--z2#', 'Two long names (aliases)') do |value|;To;;[I"!p ['--y1% or --z2#', value] ;T;0o; ;[I" end ;TI"parser.parse!;T@ o; ;[I"Executions:;T@ o;;[I""$ ruby long_simple.rb --help ;TI""Usage: long_simple [options] ;TI"8 --xxx One long name ;TI"C --y1%, --z2# Two long names (aliases) ;TI"!$ ruby long_simple.rb --xxx ;TI"["--xxx", true] ;TI"-$ ruby long_simple.rb --y1% --xxx --z2# ;TI"["--y1% or --z2#", true] ;TI"["--xxx", true] ;TI"["--y1% or --z2#", true] ;T;0S; ; i ; I"'Long Names with Required Arguments;T@ o; ;[I"File +long_required.rb+ defines an option --xxx ;TI"that requires an argument.;T@ o;;[ I"require 'optparse' ;TI"parser = OptionParser.new ;TI"Kparser.on('--xxx XXX', 'Long name with required argument') do |value| ;TI" p ['--xxx', value] ;TI" end ;TI"parser.parse! ;T;0o; ;[I"Executions:;T@ o;;[ I"$$ ruby long_required.rb --help ;TI"$Usage: long_required [options] ;TI"K --xxx XXX Long name with required argument ;TI"#$ ruby long_required.rb --xxx ;TI"]long_required.rb:6:in `
': missing argument: --xxx (OptionParser::MissingArgument) ;TI"'$ ruby long_required.rb --xxx FOO ;TI"["--xxx", "FOO"] ;T;0S; ; i ; I"'Long Names with Optional Arguments;T@ o; ;[I"OA long name followed (with whitespace) by a dummy word in square brackets ;TI"8defines an option that allows an optional argument.;T@ o; ;[I">File +long_optional.rb+ defines an option --xxx ;TI"&that allows an optional argument.;T@ o;;[ I"require 'optparse' ;TI"parser = OptionParser.new ;TI"Mparser.on('--xxx [XXX]', 'Long name with optional argument') do |value| ;TI" p ['--xxx', value] ;TI" end ;TI"parser.parse! ;T;0o; ;[I"Executions:;T@ o;;[ I"$$ ruby long_optional.rb --help ;TI"$Usage: long_optional [options] ;TI"K --xxx [XXX] Long name with optional argument ;TI"#$ ruby long_optional.rb --xxx ;TI"["--xxx", nil] ;TI"'$ ruby long_optional.rb --xxx FOO ;TI"["--xxx", "FOO"] ;T;0S; ; i ; I"Long Names with Negation;T@ o; ;[I"GA long name may be defined with both positive and negative senses.;T@ o; ;[I"IFile +long_with_negation.rb+ defines an option that has both senses.;T@ o;;[ I"require 'optparse' ;TI"parser = OptionParser.new ;TI"Fparser.on('--[no-]binary', 'Long name with negation') do |value| ;TI" p [value, value.class] ;TI" end ;TI"parser.parse! ;T;0o; ;[I"Executions:;T@ o;;[ I")$ ruby long_with_negation.rb --help ;TI")Usage: long_with_negation [options] ;TI"B --[no-]binary Long name with negation ;TI"+$ ruby long_with_negation.rb --binary ;TI"[true, TrueClass] ;TI".$ ruby long_with_negation.rb --no-binary ;TI"[false, FalseClass] ;T;0S; ; i ; I"Mixed Names;T@ o; ;[I"2An option may have both short and long names.;T@ o; ;[I"EFile +mixed_names.rb+ defines a mixture of short and long names.;T@ o;;[I"require 'optparse' ;TI"parser = OptionParser.new ;TI"Hparser.on('-x', '--xxx', 'Short and long, no argument') do |value| ;TI" p ['--xxx', value] ;TI" end ;TI"Qparser.on('-yYYY', '--yyy', 'Short and long, required argument') do |value| ;TI" p ['--yyy', value] ;TI" end ;TI"Tparser.on('-z [ZZZ]', '--zzz', 'Short and long, optional argument') do |value| ;TI" p ['--zzz', value] ;TI" end ;TI"parser.parse! ;T;0o; ;[I"Executions:;T@ o;;[I""$ ruby mixed_names.rb --help ;T;0o; ;[I"!Usage: mixed_names [options];To;;[I"D -x, --xxx Short and long, no argument ;TI"J -y, --yyyYYY Short and long, required argument ;TI"J -z, --zzz [ZZZ] Short and long, optional argument ;TI"$ ruby mixed_names.rb -x ;TI"["--xxx", true] ;TI"!$ ruby mixed_names.rb --xxx ;TI"["--xxx", true] ;TI"$ ruby mixed_names.rb -y ;TI"Ymixed_names.rb:12:in `
': missing argument: -y (OptionParser::MissingArgument) ;TI""$ ruby mixed_names.rb -y FOO ;TI"["--yyy", "FOO"] ;TI"!$ ruby mixed_names.rb --yyy ;TI"\mixed_names.rb:12:in `
': missing argument: --yyy (OptionParser::MissingArgument) ;TI"%$ ruby mixed_names.rb --yyy BAR ;TI"["--yyy", "BAR"] ;TI"$ ruby mixed_names.rb -z ;TI"["--zzz", nil] ;TI""$ ruby mixed_names.rb -z BAZ ;TI"["--zzz", "BAZ"] ;TI"!$ ruby mixed_names.rb --zzz ;TI"["--zzz", nil] ;TI"%$ ruby mixed_names.rb --zzz BAT ;TI"["--zzz", "BAT"] ;T;0S; ; i; I"Argument Keywords;T@ o; ;[I":As seen above, a given option name string may itself ;TI"Gindicate whether the option has no argument, a required argument, ;TI"or an optional argument.;T@ o; ;[I"9An alternative is to use a separate symbol keyword, ;TI"3which is one of :NONE (the default), ;TI",:REQUIRED, :OPTIONAL.;T@ o; ;[I"LFile +argument_keywords.rb+ defines an option with a required argument.;T@ o;;[ I"require 'optparse' ;TI"parser = OptionParser.new ;TI"Iparser.on('-x', '--xxx', :REQUIRED, 'Required argument') do |value| ;TI" p ['--xxx', value] ;TI" end ;TI"parser.parse! ;T;0o; ;[I"Executions:;T@ o;;[ I"($ ruby argument_keywords.rb --help ;TI"(Usage: argument_keywords [options] ;TI"< -x, --xxx Required argument ;TI"%$ ruby argument_styles.rb --xxx ;TI"_argument_styles.rb:6:in `
': missing argument: --xxx (OptionParser::MissingArgument) ;TI")$ ruby argument_styles.rb --xxx FOO ;TI"["--xxx", "FOO"] ;T;0S; ; i; I"Argument Strings;T@ o; ;[I"6Still another way to specify a required argument ;TI"?is to define it in a string separate from the name string.;T@ o; ;[I"KFile +argument_strings.rb+ defines an option with a required argument.;T@ o;;[ I"require 'optparse' ;TI"parser = OptionParser.new ;TI"Fparser.on('-x', '--xxx', '=XXX', 'Required argument') do |value| ;TI" p ['--xxx', value] ;TI" end ;TI"parser.parse! ;T;0o; ;[I"Executions:;T@ o;;[ I"'$ ruby argument_strings.rb --help ;TI"'Usage: argument_strings [options] ;TI"< -x, --xxx=XXX Required argument ;TI"&$ ruby argument_strings.rb --xxx ;TI"`argument_strings.rb:9:in `
': missing argument: --xxx (OptionParser::MissingArgument) ;TI"*$ ruby argument_strings.rb --xxx FOO ;TI"["--xxx", "FOO"] ;T;0S; ; i; I"Argument Values;T@ o; ;[I"3Permissible argument values may be restricted ;TI"*either by specifying explicit values ;TI"?or by providing a pattern that the given value must match.;T@ S; ; i ; I"Explicit Argument Values;T@ o; ;[I";You can specify argument values in either of two ways:;T@ o;;;;[o;;0;[o; ;[I"(Specify values an array of strings.;To;;0;[o; ;[I"Specify values a hash.;T@ S; ; i ; I"Explicit Values in Array;T@ o; ;[I"FYou can specify explicit argument values in an array of strings. ;TI"UThe argument value must be one of those strings, or an unambiguous abbreviation.;T@ o; ;[I"SFile +explicit_array_values.rb+ defines options with explicit argument values.;T@ o;;[I"require 'optparse' ;TI"parser = OptionParser.new ;TI"Tparser.on('-xXXX', ['foo', 'bar'], 'Values for required argument' ) do |value| ;TI" p ['-x', value] ;TI" end ;TI"Vparser.on('-y [YYY]', ['baz', 'bat'], 'Values for optional argument') do |value| ;TI" p ['-y', value] ;TI" end ;TI"parser.parse! ;T;0o; ;[I"Executions:;T@ o;;[I",$ ruby explicit_array_values.rb --help ;TI",Usage: explicit_array_values [options] ;TI"G -xXXX Values for required argument ;TI"G -y [YYY] Values for optional argument ;TI"($ ruby explicit_array_values.rb -x ;TI"bexplicit_array_values.rb:9:in `
': missing argument: -x (OptionParser::MissingArgument) ;TI",$ ruby explicit_array_values.rb -x foo ;TI"["-x", "foo"] ;TI"*$ ruby explicit_array_values.rb -x f ;TI"["-x", "foo"] ;TI",$ ruby explicit_array_values.rb -x bar ;TI"["-x", "bar"] ;TI"+$ ruby explicit_array_values.rb -y ba ;TI"iexplicit_array_values.rb:9:in `
': ambiguous argument: -y ba (OptionParser::AmbiguousArgument) ;TI",$ ruby explicit_array_values.rb -x baz ;TI"fexplicit_array_values.rb:9:in `
': invalid argument: -x baz (OptionParser::InvalidArgument) ;T;0S; ; i ; I"Explicit Values in Hash;T@ o; ;[I"JYou can specify explicit argument values in a hash with string keys. ;TI"QThe value passed must be one of those keys, or an unambiguous abbreviation; ;TI"6the value yielded will be the value for that key.;T@ o; ;[I"RFile +explicit_hash_values.rb+ defines options with explicit argument values.;T@ o;;[I"require 'optparse' ;TI"parser = OptionParser.new ;TI"Vparser.on('-xXXX', {foo: 0, bar: 1}, 'Values for required argument' ) do |value| ;TI" p ['-x', value] ;TI" end ;TI"Xparser.on('-y [YYY]', {baz: 2, bat: 3}, 'Values for optional argument') do |value| ;TI" p ['-y', value] ;TI" end ;TI"parser.parse! ;T;0o; ;[I"Executions:;T@ o;;[I"+$ ruby explicit_hash_values.rb --help ;TI"+Usage: explicit_hash_values [options] ;TI"G -xXXX Values for required argument ;TI"G -y [YYY] Values for optional argument ;TI"'$ ruby explicit_hash_values.rb -x ;TI"aexplicit_hash_values.rb:9:in `
': missing argument: -x (OptionParser::MissingArgument) ;TI"+$ ruby explicit_hash_values.rb -x foo ;TI"["-x", 0] ;TI")$ ruby explicit_hash_values.rb -x f ;TI"["-x", 0] ;TI"+$ ruby explicit_hash_values.rb -x bar ;TI"["-x", 1] ;TI"+$ ruby explicit_hash_values.rb -x baz ;TI"eexplicit_hash_values.rb:9:in `
': invalid argument: -x baz (OptionParser::InvalidArgument) ;TI"'$ ruby explicit_hash_values.rb -y ;TI"["-y", nil] ;TI"+$ ruby explicit_hash_values.rb -y baz ;TI"["-y", 2] ;TI"+$ ruby explicit_hash_values.rb -y bat ;TI"["-y", 3] ;TI"*$ ruby explicit_hash_values.rb -y ba ;TI"hexplicit_hash_values.rb:9:in `
': ambiguous argument: -y ba (OptionParser::AmbiguousArgument) ;TI"+$ ruby explicit_hash_values.rb -y bam ;TI"["-y", nil] ;T;0S; ; i ; I"Argument Value Patterns;T@ o; ;[I"2You can restrict permissible argument values ;TI"?by specifying a Regexp that the given argument must match.;T@ o; ;[I"KFile +matched_values.rb+ defines options with matched argument values.;T@ o;;[ I"require 'optparse' ;TI"parser = OptionParser.new ;TI"Aparser.on('--xxx XXX', /foo/i, 'Matched values') do |value| ;TI" p ['--xxx', value] ;TI" end ;TI"parser.parse! ;T;0o; ;[I"Executions:;T@ o;;[I"%$ ruby matched_values.rb --help ;TI"%Usage: matched_values [options] ;TI"9 --xxx XXX Matched values ;TI"($ ruby matched_values.rb --xxx foo ;TI"["--xxx", "foo"] ;TI"($ ruby matched_values.rb --xxx FOO ;TI"["--xxx", "FOO"] ;TI"($ ruby matched_values.rb --xxx bar ;TI"bmatched_values.rb:6:in `
': invalid argument: --xxx bar (OptionParser::InvalidArgument) ;T;0S; ; i; I"Argument Converters;T@ o; ;[I"@An option can specify that its argument is to be converted ;TI"?from the default +String+ to an instance of another class.;T@ o; ;[I"0There are a number of built-in converters. ;TI"+You can also define custom converters.;T@ o; ;[I";See {Argument Converters}[./argument_converters.rdoc].;T@ S; ; i; I"Descriptions;T@ o; ;[ I"5A description parameter is any string parameter ;TI""that is not recognized as an ;TI"-{option name}[#label-Option+Names] or a ;TI"'{terminator}[#label-Terminators]; ;TI"5in other words, it does not begin with a hyphen.;T@ o; ;[I"8You may give any number of description parameters; ;TI"Ieach becomes a line in the text generated by option --help.;T@ o; ;[I"IFile +descriptions.rb+ has six strings in its array +descriptions+. ;TI"IThese are all passed as parameters to OptionParser#on, so that they ;TI"9all, line for line, become the option's description.;T@ o;;[I"require 'optparse' ;TI"parser = OptionParser.new ;TI"description = <<-EOT ;TI".Lorem ipsum dolor sit amet, consectetuer ;TI"2adipiscing elit. Aenean commodo ligula eget. ;TI"0Aenean massa. Cum sociis natoque penatibus ;TI"/et magnis dis parturient montes, nascetur ;TI"0ridiculus mus. Donec quam felis, ultricies ;TI".nec, pellentesque eu, pretium quis, sem. ;TI" EOT ;TI"*descriptions = description.split($/) ;TI"2parser.on('--xxx', *descriptions) do |value| ;TI" p ['--xxx', value] ;TI" end ;TI"parser.parse! ;T;0o; ;[I"Executions:;T@ o;;[I"#$ ruby descriptions.rb --help ;TI"#Usage: descriptions [options] ;TI"S --xxx Lorem ipsum dolor sit amet, consectetuer ;TI"W adipiscing elit. Aenean commodo ligula eget. ;TI"U Aenean massa. Cum sociis natoque penatibus ;TI"T et magnis dis parturient montes, nascetur ;TI"U ridiculus mus. Donec quam felis, ultricies ;TI"S nec, pellentesque eu, pretium quis, sem. ;TI""$ ruby descriptions.rb --xxx ;TI"["--xxx", true] ;T;0S; ; i; I"Option Handlers;T@ o; ;[I"DThe handler for an option is an executable that will be called ;TI"9when the option is encountered. The handler may be:;T@ o;;;;[o;;0;[o; ;[I"'A block (this is most often seen).;To;;0;[o; ;[I" A proc.;To;;0;[o; ;[I"A method.;T@ S; ; i ; I"Handler Blocks;T@ o; ;[I"&An option handler may be a block.;T@ o; ;[I"@File +block.rb+ defines an option that has a handler block.;T@ o;;[I"require 'optparse' ;TI"parser = OptionParser.new ;TI">parser.on('--xxx', 'Option with no argument') do |value| ;TI"> p ['Handler block for -xxx called with value:', value] ;TI" end ;TI"Hparser.on('--yyy YYY', 'Option with required argument') do |value| ;TI"> p ['Handler block for -yyy called with value:', value] ;TI" end ;TI"parser.parse! ;T;0o; ;[I"Executions:;T@ o;;[ I"$ ruby block.rb --help ;TI"Usage: block [options] ;TI"B --xxx Option with no argument ;TI"H --yyy YYY Option with required argument ;TI"$ ruby block.rb --xxx ;TI"9["Handler block for -xxx called with value:", true] ;TI"$ ruby block.rb --yyy FOO ;TI":["Handler block for -yyy called with value:", "FOO"] ;T;0S; ; i ; I"Handler Procs;T@ o; ;[I"%An option handler may be a Proc.;T@ o; ;[I">File +proc.rb+ defines an option that has a handler proc.;T@ o;;[I"require 'optparse' ;TI"parser = OptionParser.new ;TI"parser.on( ;TI" '--xxx', ;TI"" 'Option with no argument', ;TI"I ->(value) {p ['Handler proc for -xxx called with value:', value]} ;TI") ;TI"parser.on( ;TI" '--yyy YYY', ;TI"( 'Option with required argument', ;TI"I ->(value) {p ['Handler proc for -yyy called with value:', value]} ;TI") ;TI"parser.parse! ;T;0o; ;[I"Executions:;T@ o;;[ I"$ ruby proc.rb --help ;TI"Usage: proc [options] ;TI"B --xxx Option with no argument ;TI"H --yyy YYY Option with required argument ;TI"$ ruby proc.rb --xxx ;TI"8["Handler proc for -xxx called with value:", true] ;TI"$ ruby proc.rb --yyy FOO ;TI"9["Handler proc for -yyy called with value:", "FOO"] ;T;0S; ; i ; I"Handler Methods;T@ o; ;[I"'An option handler may be a Method.;T@ o; ;[I"@File +proc.rb+ defines an option that has a handler method.;T@ o;;[I"require 'optparse' ;TI"parser = OptionParser.new ;TI"def xxx_handler(value) ;TI"? p ['Handler method for -xxx called with value:', value] ;TI" end ;TI"Iparser.on('--xxx', 'Option with no argument', method(:xxx_handler)) ;TI"def yyy_handler(value) ;TI"? p ['Handler method for -yyy called with value:', value] ;TI" end ;TI"Sparser.on('--yyy YYY', 'Option with required argument', method(:yyy_handler)) ;TI"parser.parse! ;T;0o; ;[I"Executions:;T@ o;;[ I"$ ruby method.rb --help ;TI"Usage: method [options] ;TI"B --xxx Option with no argument ;TI"H --yyy YYY Option with required argument ;TI"$ ruby method.rb --xxx ;TI":["Handler method for -xxx called with value:", true] ;TI" $ ruby method.rb --yyy FOO ;TI":["Handler method for -yyy called with value:", "FOO"];T;0: @file@:0@omit_headings_from_table_of_contents_below0