[前][次][番号順一覧][スレッド一覧]

ruby-changes:65695

From: BurdetteLamar <ko1@a...>
Date: Mon, 29 Mar 2021 19:42:00 +0900 (JST)
Subject: [ruby-changes:65695] 7846f3201a (master): [ruby/optparse] Change *opts to *params, to avoid confusion

https://git.ruby-lang.org/ruby.git/commit/?id=7846f3201a

From 7846f3201a1381cf07ff7477b8a1d6744a853c78 Mon Sep 17 00:00:00 2001
From: BurdetteLamar <burdettelamar@y...>
Date: Sun, 28 Mar 2021 12:24:21 -0500
Subject: [ruby/optparse] Change *opts to *params, to avoid confusion

https://github.com/ruby/optparse/commit/f5f5e202dd
---
 lib/optparse.rb        | 45 ++++++++++++++++++++++++++++++++-------------
 lib/optparse/kwargs.rb |  3 +++
 2 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/lib/optparse.rb b/lib/optparse.rb
index af12e42..8b09915 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -72,10 +72,10 @@ https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L72
 #   require 'optparse'
 #
 #   options = {}
-#   OptionParser.new do |opts|
-#     opts.banner = "Usage: example.rb [options]"
+#   OptionParser.new do |parser|
+#     parser.banner = "Usage: example.rb [options]"
 #
-#     opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
+#     parser.on("-v", "--[no-]verbose", "Run verbosely") do |v|
 #       options[:verbose] = v
 #     end
 #   end.parse!
@@ -96,15 +96,15 @@ https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L96
 #     def self.parse(options)
 #       args = Options.new("world")
 #
-#       opt_parser = OptionParser.new do |opts|
-#         opts.banner = "Usage: example.rb [options]"
+#       opt_parser = OptionParser.new do |parser|
+#         parser.banner = "Usage: example.rb [options]"
 #
-#         opts.on("-nNAME", "--name=NAME", "Name to say hello to") do |n|
+#         parser.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
+#         parser.on("-h", "--help", "Prints this help") do
+#           puts parser
 #           exit
 #         end
 #       end
@@ -241,10 +241,10 @@ https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L241
 #   require 'optparse'
 #
 #   params = {}
-#   OptionParser.new do |opts|
-#     opts.on('-a')
-#     opts.on('-b NUM', Integer)
-#     opts.on('-v', '--verbose')
+#   OptionParser.new do |parser|
+#     parser.on('-a')
+#     parser.on('-b NUM', Integer)
+#     parser.on('-v', '--verbose')
 #   end.parse!(into: params)
 #
 #   p params
@@ -1310,13 +1310,16 @@ XXX https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L1310
   private :notwice
 
   SPLAT_PROC = proc {|*a| a.length <= 1 ? a.first : a} # :nodoc:
+
+  # :call-seq:
+  #   make_switch(params, block = nil)
   #
   # Creates an OptionParser::Switch from the parameters. The parsed argument
   # value is passed to the given block, where it can be processed.
   #
   # See at the beginning of OptionParser for some full examples.
   #
-  # +opts+ can include the following elements:
+  # +params+ can include the following elements:
   #
   # [Argument style:]
   #   One of the following:
@@ -1503,11 +1506,16 @@ XXX https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L1506
       nolong
   end
 
+  # :call-seq:
+  #   define(*params, &block)
+  #
   def define(*opts, &block)
     top.append(*(sw = make_switch(opts, block)))
     sw[0]
   end
 
+  # :call-seq:
+  #   on(*params, &block)
   #
   # Add option switch and handler. See #make_switch for an explanation of
   # parameters.
@@ -1518,11 +1526,16 @@ XXX https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L1526
   end
   alias def_option define
 
+  # :call-seq:
+  #   define_head(*params, &block)
+  #
   def define_head(*opts, &block)
     top.prepend(*(sw = make_switch(opts, block)))
     sw[0]
   end
 
+  # :call-seq:
+  #   on_head(*params, &block)
   #
   # Add option switch like with #on, but at head of summary.
   #
@@ -1532,12 +1545,18 @@ XXX https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L1545
   end
   alias def_head_option define_head
 
+  # :call-seq:
+  #   define_tail(*params, &block)
+  #
   def define_tail(*opts, &block)
     base.append(*(sw = make_switch(opts, block)))
     sw[0]
   end
 
   #
+  # :call-seq:
+  #   on_tail(*params, &block)
+  #
   # Add option switch like with #on, but at tail of summary.
   #
   def on_tail(*opts, &block)
diff --git a/lib/optparse/kwargs.rb b/lib/optparse/kwargs.rb
index ed58cc1..5a2def4 100644
--- a/lib/optparse/kwargs.rb
+++ b/lib/optparse/kwargs.rb
@@ -2,6 +2,9 @@ https://github.com/ruby/ruby/blob/trunk/lib/optparse/kwargs.rb#L2
 require 'optparse'
 
 class OptionParser
+  # :call-seq:
+  #   define_by_keywords(options, method, **params)
+  #
   def define_by_keywords(options, meth, **opts)
     meth.parameters.each do |type, name|
       case type
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]