diff --git a/doc/optparse/argument_converters.rdoc b/doc/optparse/argument_converters.rdoc index 5327298..bafced4 100644 --- a/doc/optparse/argument_converters.rdoc +++ b/doc/optparse/argument_converters.rdoc @@ -1,9 +1,9 @@ -== Argument Converters += Argument Converters An option can specify that its argument is to be converted from the default +String+ to an instance of another class. -=== Contents +== Contents - {Built-In Argument Converters}[#label-Built-In+Argument+Converters] - {Date}[#label-Date] @@ -25,12 +25,12 @@ from the default +String+ to an instance of another class. - {Regexp}[#label-Regexp] - {Custom Argument Converters}[#label-Custom+Argument+Converters] -=== Built-In Argument Converters +== Built-In Argument Converters +OptionParser+ has a number of built-in argument converters, which are demonstrated below. -==== +Date+ +=== +Date+ File +date.rb+ defines an option whose argument is to be converted to a +Date+ object. @@ -47,7 +47,7 @@ Executions: $ ruby date.rb --date "3rd Feb 2001" [#, Date] -==== +DateTime+ +=== +DateTime+ File +datetime.rb+ defines an option whose argument is to be converted to a +DateTime+ object. @@ -64,7 +64,7 @@ Executions: $ ruby datetime.rb --datetime "3rd Feb 2001 04:05:06 PM" [#, DateTime] -==== +Time+ +=== +Time+ File +time.rb+ defines an option whose argument is to be converted to a +Time+ object. @@ -79,7 +79,7 @@ Executions: $ ruby time.rb --time 2010-10-31 [2010-10-31 00:00:00 -0500, Time] -==== +URI+ +=== +URI+ File +uri.rb+ defines an option whose argument is to be converted to a +URI+ object. @@ -96,7 +96,7 @@ Executions: $ ruby uri.rb --uri file://~/var [#, URI::File] -==== +Shellwords+ +=== +Shellwords+ File +shellwords.rb+ defines an option whose argument is to be converted to an +Array+ object by method @@ -111,7 +111,7 @@ Executions: $ ruby shellwords.rb --shellwords "here are 'two words'" [["here", "are", "two words"], Array] -==== +Integer+ +=== +Integer+ File +integer.rb+ defines an option whose argument is to be converted to an +Integer+ object. @@ -132,7 +132,7 @@ Executions: $ ruby integer.rb --integer 0b100 [4, Integer] -==== +Float+ +=== +Float+ File +float.rb+ defines an option whose argument is to be converted to a +Float+ object. @@ -151,7 +151,7 @@ Executions: $ ruby float.rb --float 1.234E-2 [0.01234, Float] -==== +Numeric+ +=== +Numeric+ File +numeric.rb+ defines an option whose argument is to be converted to an instance @@ -170,7 +170,7 @@ Executions: $ ruby numeric.rb --numeric 3 [3, Integer] -==== +DecimalInteger+ +=== +DecimalInteger+ File +decimal_integer.rb+ defines an option whose argument is to be converted to an +Integer+ object. @@ -192,7 +192,7 @@ Executions: $ ruby decimal_integer.rb --decimal_integer -0100 [-100, Integer] -==== +OctalInteger+ +=== +OctalInteger+ File +octal_integer.rb+ defines an option whose argument is to be converted to an +Integer+ object. @@ -212,7 +212,7 @@ Executions: $ ruby octal_integer.rb --octal_integer 0100 [64, Integer] -==== +DecimalNumeric+ +=== +DecimalNumeric+ File +decimal_numeric.rb+ defines an option whose argument is to be converted to an +Integer+ object. @@ -232,7 +232,7 @@ Executions: $ ruby decimal_numeric.rb --decimal_numeric 0100 [64, Integer] -==== +TrueClass+ +=== +TrueClass+ File +true_class.rb+ defines an option whose argument is to be converted to +true+ or +false+. @@ -259,7 +259,7 @@ Executions: $ ruby true_class.rb --true_class nil [false, FalseClass] -==== +FalseClass+ +=== +FalseClass+ File +false_class.rb+ defines an option whose argument is to be converted to +true+ or +false+. @@ -286,7 +286,7 @@ Executions: $ ruby false_class.rb --false_class + [true, TrueClass] -==== +Object+ +=== +Object+ File +object.rb+ defines an option whose argument is not to be converted from +String+. @@ -300,7 +300,7 @@ Executions: $ ruby object.rb --object nil ["nil", String] -==== +String+ +=== +String+ File +string.rb+ defines an option whose argument is not to be converted from +String+. @@ -314,7 +314,7 @@ Executions: $ ruby string.rb --string nil ["nil", String] -==== +Array+ +=== +Array+ File +array.rb+ defines an option whose argument is to be converted from +String+ @@ -331,7 +331,7 @@ Executions: $ ruby array.rb --array "foo, bar, baz" [["foo", " bar", " baz"], Array] -==== +Regexp+ +=== +Regexp+ File +regexp.rb+ defines an option whose argument is to be converted to a +Regexp+ object. @@ -342,7 +342,7 @@ Executions: $ ruby regexp.rb --regexp foo -=== Custom Argument Converters +== Custom Argument Converters You can create custom argument converters. To create a custom converter, call OptionParser#accept with: diff --git a/doc/optparse/option_params.rdoc b/doc/optparse/option_params.rdoc index 575ee66..3d0c398 100644 --- a/doc/optparse/option_params.rdoc +++ b/doc/optparse/option_params.rdoc @@ -1,4 +1,4 @@ -== Parameters for New Options += Parameters for New Options Option-creating methods in +OptionParser+ accept arguments that determine the behavior of a new option: @@ -44,16 +44,16 @@ Contents: - {Handler Procs}[#label-Handler+Procs] - {Handler Methods}[#label-Handler+Methods] -=== Option Names +== Option Names There are two kinds of option names: - Short option name, consisting of a single hyphen and a single character. - Long option name, consisting of two hyphens and one or more characters. -==== Short Names +=== Short Names -===== Simple Short Names +==== Simple Short Names File +short_simple.rb+ defines two options: @@ -75,7 +75,7 @@ Executions: ["-x", true] ["-1 or -%", true] -===== Short Names with Required Arguments +==== Short Names with Required Arguments A short name followed (no whitespace) by a dummy word defines an option that requires an argument. @@ -95,7 +95,7 @@ Executions: $ ruby short_required.rb -x FOO ["-x", "FOO"] -===== Short Names with Optional Arguments +==== Short Names with Optional Arguments A short name followed (with whitespace) by a dummy word in square brackets defines an option that allows an optional argument. @@ -115,7 +115,7 @@ Executions: $ ruby short_optional.rb -x FOO ["-x", "FOO"] -===== Short Names from Range +==== Short Names from Range You can define an option with multiple short names taken from a range of characters. @@ -140,9 +140,9 @@ Executions: $ ruby short_range.rb -z ["!-~", "z", nil] -==== Long Names +=== Long Names -===== Simple Long Names +==== Simple Long Names File +long_simple.rb+ defines two options: @@ -165,7 +165,7 @@ Executions: ["--xxx", true] ["--y1% or --z2#", true] -===== Long Names with Required Arguments +==== Long Names with Required Arguments A long name followed (with whitespace) by a dummy word defines an option that requires an argument. @@ -185,7 +185,7 @@ Executions: $ ruby long_required.rb --xxx FOO ["--xxx", "FOO"] -===== Long Names with Optional Arguments +==== Long Names with Optional Arguments A long name followed (with whitespace) by a dummy word in square brackets defines an option that allows an optional argument. @@ -205,7 +205,7 @@ Executions: $ ruby long_optional.rb --xxx FOO ["--xxx", "FOO"] -===== Long Names with Negation +==== Long Names with Negation A long name may be defined with both positive and negative senses. @@ -223,7 +223,7 @@ Executions: $ ruby long_with_negation.rb --no-binary [false, FalseClass] -==== Mixed Names +=== Mixed Names An option may have both short and long names. @@ -259,7 +259,7 @@ Usage: mixed_names [options] $ ruby mixed_names.rb --zzz BAT ["--zzz", "BAT"] -=== Argument Keywords +== Argument Keywords As seen above, a given option name string may itself indicate whether the option has no argument, a required argument, @@ -283,7 +283,7 @@ Executions: $ ruby argument_styles.rb --xxx FOO ["--xxx", "FOO"] -=== Argument Strings +== Argument Strings Still another way to specify a required argument is to define it in a string separate from the name string. @@ -302,20 +302,20 @@ Executions: $ ruby argument_strings.rb --xxx FOO ["--xxx", "FOO"] -=== Argument Values +== Argument Values Permissible argument values may be restricted either by specifying explicit values or by providing a pattern that the given value must match. -==== Explicit Argument Values +=== Explicit Argument Values You can specify argument values in either of two ways: - Specify values an array of strings. - Specify values a hash. -===== Explicit Values in Array +==== Explicit Values in Array You can specify explicit argument values in an array of strings. The argument value must be one of those strings, or an unambiguous abbreviation. @@ -344,7 +344,7 @@ Executions: explicit_array_values.rb:9:in '
': invalid argument: -x baz (OptionParser::InvalidArgument) -===== Explicit Values in Hash +==== Explicit Values in Hash You can specify explicit argument values in a hash with string keys. The value passed must be one of those keys, or an unambiguous abbreviation; @@ -381,7 +381,7 @@ Executions: $ ruby explicit_hash_values.rb -y bam ["-y", nil] -==== Argument Value Patterns +=== Argument Value Patterns You can restrict permissible argument values by specifying a +Regexp+ that the given argument must match, @@ -413,7 +413,7 @@ Executions: $ ruby matched_values.rb --zzz 2 matched_values.rb:12:in '
': invalid argument: --zzz 2 (OptionParser::InvalidArgument) -=== Argument Converters +== Argument Converters An option can specify that its argument is to be converted from the default +String+ to an instance of another class. @@ -423,7 +423,7 @@ You can also define custom converters. See {Argument Converters}[./argument_converters.rdoc]. -=== Descriptions +== Descriptions A description parameter is any string parameter that is not recognized as an @@ -453,7 +453,7 @@ Executions: $ ruby descriptions.rb --xxx ["--xxx", true] -=== Option Handlers +== Option Handlers The handler for an option is an executable that will be called when the option is encountered. The handler may be: @@ -462,7 +462,7 @@ when the option is encountered. The handler may be: - A proc. - A method. -==== Handler Blocks +=== Handler Blocks An option handler may be a block. @@ -481,7 +481,7 @@ Executions: $ ruby block.rb --yyy FOO ["Handler block for -yyy called with value:", "FOO"] -==== Handler Procs +=== Handler Procs An option handler may be a Proc. @@ -500,7 +500,7 @@ Executions: $ ruby proc.rb --yyy FOO ["Handler proc for -yyy called with value:", "FOO"] -==== Handler Methods +=== Handler Methods An option handler may be a Method.