From 5c0e6cc886abb26ab02c40de5ad217595f6e9b82 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 12 May 2018 14:41:24 +0000 Subject: [PATCH] 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) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63410 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/optparse.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/optparse.rb b/lib/optparse.rb index 2a2098e256..31d18aee35 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -232,6 +232,29 @@ # # # 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