mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
optparse.rb: [DOC] about into: option
* lib/optparse.rb: add documentation for "into" option of #parse and family, which stores options to a Hash. [ruby-core:87004] [Misc #14753] From: pocke (Masataka Kuwabara) <kuwabara@pocke.me> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63410 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
707c5ffab5
commit
5c0e6cc886
1 changed files with 23 additions and 0 deletions
|
@ -232,6 +232,29 @@
|
|||
# #<struct User id=2, name="Gandalf">
|
||||
# bash-3.2$ ruby optparse-test.rb --user 3
|
||||
# optparse-test.rb:15:in `block in find_user': No User Found for id 3 (RuntimeError)
|
||||
#
|
||||
# === Store options to a Hash
|
||||
#
|
||||
# The +into+ option of +order+, +parse+ and so on methods stores command line options into a Hash.
|
||||
#
|
||||
# require 'optparse'
|
||||
#
|
||||
# params = {}
|
||||
# OptionParser.new do |opts|
|
||||
# opts.on('-a')
|
||||
# opts.on('-b NUM', Integer)
|
||||
# opts.on('-v', '--verbose')
|
||||
# end.parse!(into: params)
|
||||
# p params
|
||||
#
|
||||
# output:
|
||||
# bash-3.2$ ruby optparse-test.rb -a
|
||||
# {:a=>true}
|
||||
# bash-3.2$ ruby optparse-test.rb -a -v
|
||||
# {:a=>true, :verbose=>true}
|
||||
# $ ruby optparse-test.rb -a -b 100
|
||||
# {:a=>true, :b=>100}
|
||||
#
|
||||
# === Complete example
|
||||
#
|
||||
# The following example is a complete Ruby program. You can run it and see the
|
||||
|
|
Loading…
Reference in a new issue