Class: Ame::Arguments::Optional

Inherits:
Undefined show all
Defined in:
lib/ame-1.0/arguments/optional.rb

Overview

The arguments to a method in its undefined state where at least one optional argument has been defined and only further #optional or #splat arguments are allowed.

Instance Method Summary collapse

Methods inherited from Undefined

#define, #empty?, #splat

Constructor Details

#initialize(arguments, optional) ⇒ Optional

Returns a new instance of Optional.



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

def initialize(arguments, optional)
  @arguments, @optional = arguments + [optional], optional
end

Instance Method Details

#argument(name, type, description, &validate) ⇒ Object

Raises:

  • (ArgumentError)

    If an optional argument has been defined



14
15
16
17
# File 'lib/ame-1.0/arguments/optional.rb', line 14

def argument(name, type, description, &validate)
  raise ArgumentError,
    "argument '%s', … may not follow optional '%s', …" % [name, @optional.name]
end

#optional(name, default, description) {|?| ... } ⇒ self

Adds a new Ame::Arguments::Optional argument to the receiver.

Parameters:

  • default (Object)
  • name (String)
  • type (::Class)
  • description (String)

Yields:

  • (?)

Yield Parameters:

  • options (Hash<String, Object>)
  • processed (Array<String>)
  • argument (Object)

Returns:

  • (self)

Raises:

  • (ArgumentError)

    If the type of DEFAULT isn’t one that Ame knows how to parse



31
32
33
# File 'lib/ame-1.0/arguments/optional.rb', line 31

def optional(name, default, description, &validate)
  self << Ame::Optional.new(name, default, description, &validate)
end

#splus(name, default, description, &validate) ⇒ Object

Raises:

  • (ArgumentError)

    If an optional argument has been defined



20
21
22
23
# File 'lib/ame-1.0/arguments/optional.rb', line 20

def splus(name, default, description, &validate)
  raise ArgumentError,
    "splus '%s', … may not follow optional '%s', …" % [name, @optional.name]
end