Sha256: b6706b90792e14916d5e11ce7acab464a38b18071ac8768fc0444894ba42396a

Contents?: true

Size: 716 Bytes

Versions: 2

Compression:

Stored size: 716 Bytes

Contents

# frozen_string_literal: true
require_relative '../optparse'

class OptionParser
  # :call-seq:
  #   define_by_keywords(options, method, **params)
  #
  # :include: ../../doc/optparse/creates_option.rdoc
  #
  # 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}", *params[name]) do |o|
          options[name] = o
        end
      end
    end
    options
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
optparse-0.6.0 lib/optparse/kwargs.rb
optparse-0.5.0 lib/optparse/kwargs.rb