diff options
Diffstat (limited to 'doc/optparse/argument_converters.rdoc')
-rw-r--r-- | doc/optparse/argument_converters.rdoc | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/doc/optparse/argument_converters.rdoc b/doc/optparse/argument_converters.rdoc index fc5a0152a3..8ad29ebc12 100644 --- a/doc/optparse/argument_converters.rdoc +++ b/doc/optparse/argument_converters.rdoc @@ -345,8 +345,14 @@ Executions: === Custom Argument Converters You can create custom argument converters. -To create a custom converter, call OptionParser#accept with a class argument, -along with a block that converts the argument and returns the converted value. +To create a custom converter, call OptionParser#accept with: + +- An identifier, which may be any object. +- An optional match pattern, which defaults to <tt>/.*/m</tt>. +- A block that accepts the argument and returns the converted value. + +This custom converter accepts any argument and converts it, +if possible, to a \Complex object. :include: ruby/custom_converter.rb @@ -360,3 +366,15 @@ Executions: [(1+2i), Complex] $ ruby custom_converter.rb --complex 0.3-0.5i [(0.3-0.5i), Complex] + +This custom converter accepts any 1-word argument +and capitalizes it, if possible. + + :include: ruby/match_converter.rb + +Executions: + + $ ruby match_converter.rb --capitalize foo + ["Foo", String] + $ ruby match_converter.rb --capitalize "foo bar" + match_converter.rb:9:in `<main>': invalid argument: --capitalize foo bar (OptionParser::InvalidArgument) |