summaryrefslogtreecommitdiff
path: root/lib/optparse.rb
diff options
context:
space:
mode:
authorstomar <stomar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-16 18:55:28 +0000
committerstomar <stomar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-16 18:55:28 +0000
commitdb4cba88d90d6700dfaffc72fa07fe6df7d06f70 (patch)
treea3d65f4e3f4814b1c5eae98c69358b2db9670c9d /lib/optparse.rb
parenta667fe79ead7714c8c563da882a4bb5f9fd1d6f4 (diff)
lib/optparse.rb: improve docs
* lib/optparse.rb: [DOC] simplify shell prompt in examples; other minor improvements. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63445 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/optparse.rb')
-rw-r--r--lib/optparse.rb31
1 files changed, 17 insertions, 14 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb
index 955f9db778..d3e8bf3981 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -125,6 +125,7 @@
# For options that require an argument, option specification strings may include an
# option name in all caps. If an option is used without the required argument,
# an exception will be raised.
+#
# require 'optparse'
#
# options = {}
@@ -137,9 +138,9 @@
#
# Used:
#
-# bash-3.2$ ruby optparse-test.rb -r
+# $ ruby optparse-test.rb -r
# optparse-test.rb:9:in `<main>': missing argument: -r (OptionParser::MissingArgument)
-# bash-3.2$ ruby optparse-test.rb -r my-library
+# $ ruby optparse-test.rb -r my-library
# You required my-library!
#
# === Type Coercion
@@ -187,13 +188,12 @@
# end.parse!
#
# Used:
-# bash-3.2$ ruby optparse-test.rb -t nonsense
+#
+# $ ruby optparse-test.rb -t nonsense
# ... invalid argument: -t nonsense (OptionParser::InvalidArgument)
-# from ... time.rb:5:in `block in <top (required)>'
-# from optparse-test.rb:31:in `<main>'
-# bash-3.2$ ruby optparse-test.rb -t 10-11-12
+# $ ruby optparse-test.rb -t 10-11-12
# 2010-11-12 00:00:00 -0500
-# bash-3.2$ ruby optparse-test.rb -t 9:30
+# $ ruby optparse-test.rb -t 9:30
# 2014-08-13 09:30:00 -0400
#
# ==== Creating Custom Conversions
@@ -225,12 +225,13 @@
#
# op.parse!
#
-# output:
-# bash-3.2$ ruby optparse-test.rb --user 1
+# Used:
+#
+# $ ruby optparse-test.rb --user 1
# #<struct User id=1, name="Sam">
-# bash-3.2$ ruby optparse-test.rb --user 2
+# $ ruby optparse-test.rb --user 2
# #<struct User id=2, name="Gandalf">
-# bash-3.2$ ruby optparse-test.rb --user 3
+# $ 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
@@ -245,12 +246,14 @@
# opts.on('-b NUM', Integer)
# opts.on('-v', '--verbose')
# end.parse!(into: params)
+#
# p params
#
-# output:
-# bash-3.2$ ruby optparse-test.rb -a
+# Used:
+#
+# $ ruby optparse-test.rb -a
# {:a=>true}
-# bash-3.2$ ruby optparse-test.rb -a -v
+# $ ruby optparse-test.rb -a -v
# {:a=>true, :verbose=>true}
# $ ruby optparse-test.rb -a -b 100
# {:a=>true, :b=>100}