Skip to content

Commit

Permalink
[DOC] Add description of OptionParser#define_by_keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Feb 11, 2024
1 parent 33956ce commit 451dea5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/optparse/kwargs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ class OptionParser
#
# :include: ../../doc/optparse/creates_option.rdoc
#
def define_by_keywords(options, meth, **opts)
meth.parameters.each do |type, name|
# Defines options which set in to _options_ for keyword parameters
# of _method_.
#
# Parameters for each keywords are given as elements of _params_.
#
def define_by_keywords(options, method, **params)
method.parameters.each do |type, name|
case type
when :key, :keyreq
op, cl = *(type == :key ? %w"[ ]" : ["", ""])
define("--#{name}=#{op}#{name.upcase}#{cl}", *opts[name]) do |o|
define("--#{name}=#{op}#{name.upcase}#{cl}", *params[name]) do |o|
options[name] = o
end
end
Expand Down

0 comments on commit 451dea5

Please sign in to comment.