summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-12 14:41:24 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-12 14:41:24 +0000
commit5c0e6cc886abb26ab02c40de5ad217595f6e9b82 (patch)
tree279f8cacf0bdc6c018fc9627506365f0d8ef941c /lib
parent707c5ffab5e2ae5105c7d9823411332b160f33df (diff)
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
Diffstat (limited to 'lib')
-rw-r--r--lib/optparse.rb23
1 files changed, 23 insertions, 0 deletions
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 @@
# #<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