mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/optparse] Tutorial: explain custom argument converters (https://github.com/ruby/optparse/pull/19)
385dd4322d
This commit is contained in:
parent
bf175e7ec2
commit
a15f0b9fe2
4 changed files with 83 additions and 4 deletions
16
doc/optparse/ruby/basic.rb
Normal file
16
doc/optparse/ruby/basic.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Require the OptionParser code.
|
||||
require 'optparse'
|
||||
# Create an OptionParser object.
|
||||
parser = OptionParser.new
|
||||
# Define one or more options.
|
||||
parser.on('-x', 'Whether to X') do |value|
|
||||
p ['x', value]
|
||||
end
|
||||
parser.on('-y', 'Whether to Y') do |value|
|
||||
p ['y', value]
|
||||
end
|
||||
parser.on('-z', 'Whether to Z') do |value|
|
||||
p ['z', value]
|
||||
end
|
||||
# Parse the command line.
|
||||
parser.parse!
|
Loading…
Add table
Add a link
Reference in a new issue