ruby-changes:51203
From: nobu <ko1@a...>
Date: Sat, 12 May 2018 23:41:30 +0900 (JST)
Subject: [ruby-changes:51203] nobu:r63410 (trunk): optparse.rb: [DOC] about into: option
nobu 2018-05-12 23:41:24 +0900 (Sat, 12 May 2018) New Revision: 63410 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63410 Log: 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@p...> Modified files: trunk/lib/optparse.rb Index: lib/optparse.rb =================================================================== --- lib/optparse.rb (revision 63409) +++ lib/optparse.rb (revision 63410) @@ -232,6 +232,29 @@ https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L232 # #<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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/