* lib/optparse.rb: [DOC] Add example of generating help with optparse.
Patch by @joelmccracken documenting-ruby/ruby#19 https://github.com/documenting-ruby/ruby/pull/19 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8f1d721810
commit
a9625a2f8a
@ -1,3 +1,9 @@
|
|||||||
|
Thu Feb 27 17:59:01 2014 Zachary Scott <e@zzak.io>
|
||||||
|
|
||||||
|
* lib/optparse.rb: [DOC] Add example of generating help with optparse.
|
||||||
|
Patch by @joelmccracken documenting-ruby/ruby#19
|
||||||
|
https://github.com/documenting-ruby/ruby/pull/19
|
||||||
|
|
||||||
Thu Feb 27 12:10:09 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Feb 27 12:10:09 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* numeric.c (ruby_num_interval_step_size): check signs and get rid
|
* numeric.c (ruby_num_interval_step_size): check signs and get rid
|
||||||
|
@ -82,6 +82,43 @@
|
|||||||
# p options
|
# p options
|
||||||
# p ARGV
|
# p ARGV
|
||||||
#
|
#
|
||||||
|
# === Generating Help
|
||||||
|
#
|
||||||
|
# OptionParser can be used to automatically generate help for the commands you
|
||||||
|
# write:
|
||||||
|
#
|
||||||
|
# require 'optparse'
|
||||||
|
#
|
||||||
|
# Options = Struct.new(:name)
|
||||||
|
#
|
||||||
|
# class Parser
|
||||||
|
# def self.parse(options)
|
||||||
|
# args = Options.new("world")
|
||||||
|
#
|
||||||
|
# opt_parser = OptionParser.new do |opts|
|
||||||
|
# opts.banner = "Usage: example.rb [options]"
|
||||||
|
#
|
||||||
|
# opts.on("-nNAME", "--name=NAME", "Name to say hello to") do |n|
|
||||||
|
# args.name = n
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# opts.on("-h", "--help", "Prints this help") do
|
||||||
|
# puts opts
|
||||||
|
# exit
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# opt_parser.parse!(options)
|
||||||
|
# return args
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# options = Parser.parse %w[--help]
|
||||||
|
#
|
||||||
|
# #=>
|
||||||
|
# # Usage: example.rb [options]
|
||||||
|
# # -n, --name=NAME Name to say hello to
|
||||||
|
# # -h, --help Prints this help#
|
||||||
|
#
|
||||||
# === Complete example
|
# === Complete example
|
||||||
#
|
#
|
||||||
# The following example is a complete Ruby program. You can run it and see the
|
# The following example is a complete Ruby program. You can run it and see the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user