Class: Ame::Arguments

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ame-1.0/arguments.rb

Overview

The arguments to a method in its defined state. Does the processing of arguments to the method and also enumerates #each of the arguments to the method for, for example, help output.

Defined Under Namespace

Classes: Complete, Optional, Undefined

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ Arguments

Returns a new instance of Arguments.



10
11
12
# File 'lib/ame-1.0/arguments.rb', line 10

def initialize(arguments)
  @arguments = arguments
end

Instance Method Details

# {|argument| ... } ⇒ Object #Enumerator<Argument>

Overloads:

  • # {|argument| ... } ⇒ Object

    Enumerates the arguments.

    Yield Parameters:

  • #Enumerator<Argument>

    Returns An Enumerator over the arguments.

    Returns:

    • (Enumerator<Argument>)

      An Enumerator over the arguments



37
38
39
40
41
42
43
# File 'lib/ame-1.0/arguments.rb', line 37

def each
  return enum_for(__method__) unless block_given?
  @arguments.each do |argument|
    yield argument
  end
  self
end

#process(options, arguments) ⇒ Array<Object>

Returns The Ame::Argument#processed arguments.

Parameters:

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

Returns:

Raises:



21
22
23
24
25
26
27
28
29
# File 'lib/ame-1.0/arguments.rb', line 21

def process(options, arguments)
  unprocessed = arguments.dup
  reduce([]){ |processed, argument|
    processed << argument.process(options, processed, unprocessed)
  }.tap{
    raise Ame::SuperfluousArgument,
      'superfluous arguments: %s' % unprocessed.join(' ') unless unprocessed.empty?
  }
end