Class: Ame::Multioption

Inherits:
Option show all
Defined in:
lib/ame-1.0/multioption.rb

Overview

Represents an option to a Method that takes an argument that can be given any number of times. If an explicit (‘=’-separated) argument is given, it’ll be used, otherwise the following argument will be used.

Instance Attribute Summary

Attributes inherited from Switch

#argument

Attributes inherited from Flag

#default, #description, #long, #short

Instance Method Summary collapse

Methods inherited from Option

#process_combined

Methods inherited from Flag

#name, #names, #process_combined

Constructor Details

#initialize(short, long, argument, type, description) {|?| ... } ⇒ Multioption

Returns a new instance of Multioption.

Parameters:

  • type (::Class)
  • argument (String)
  • default (Object)
  • argument_default (Object)
  • short (String)
  • long (String)
  • default (Boolean)
  • description (String)

Yields:

  • (?)

Yield Parameters:

  • options (Hash<String, Object>)
  • value (Object)

Raises:

  • (ArgumentError)

    If TYPE isn’t one that Ame knows how to parse

  • (ArgumentError)

    If SHORT and LONG are #strip#empty?

  • (ArgumentError)

    If SHORT#strip#length > 1



15
16
17
18
19
# File 'lib/ame-1.0/multioption.rb', line 15

def initialize(short, long, argument, type, description, &validate)
  super short, long, argument, nil, description, &validate
  @type = Ame::Types[type]
  @ignored = true
end

Instance Method Details

#ignored?Boolean

Returns True if the receiver hasn’t been asked to process any options yet.

Returns:

  • (Boolean)

    True if the receiver hasn’t been asked to process any options yet



33
34
35
# File 'lib/ame-1.0/multioption.rb', line 33

def ignored?
  @ignored
end

#process(options, arguments, name, explicit) ⇒ Object

Invokes super and adds it to an Array added to OPTIONS before returning it.

Parameters:

  • options (Hash<String, Object>)
  • arguments (Array<String>)
  • name (String)

Returns:

  • (Object)

Raises:



27
28
29
30
# File 'lib/ame-1.0/multioption.rb', line 27

def process(options, arguments, name, explicit)
  @ignored = false
  (options[self.name] ||= []) << super
end