Class: Ame::Arguments::Undefined

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

Overview

The arguments to a method in its undefined state before any optional or splat/splus arguments have been defined. When an #optional argument has been added, it’ll enter an Optional state where only additional #optional and #splat arguments are allowed. When a #splat or #splus has been added, it’ll enter a Complete state where no additional arguments are allowed.

Direct Known Subclasses

Complete, Optional

Instance Method Summary collapse

Constructor Details

#initializeUndefined

Returns a new instance of Undefined.



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

def initialize
  @arguments = []
end

Instance Method Details

#argument(name, type, description) {|?| ... } ⇒ self

Adds a new Ame::Argument to the receiver.

Parameters:

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

Yields:

  • (?)

Yield Parameters:

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

Returns:

  • (self)

Raises:

  • (ArgumentError)

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



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

def argument(name, type, description, &validate)
  self << Ame::Argument.new(name, type, description, &validate)
end

#defineArguments

Returns The defined version of the receiver.

Returns:

  • (Arguments)

    The defined version of the receiver



61
62
63
# File 'lib/ame-1.0/arguments/undefined.rb', line 61

def define
  Ame::Arguments.new(@arguments)
end

#empty?Boolean

Returns True if now arguments have been added to the receiver.

Returns:

  • (Boolean)

    True if now arguments have been added to the receiver



56
57
58
# File 'lib/ame-1.0/arguments/undefined.rb', line 56

def empty?
  @arguments.empty?
end

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

Adds a new 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:

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/undefined.rb', line 31

def optional(name, default, description, &validate)
  Ame::Arguments::Optional.new(@arguments, Ame::Optional.new(name, default, description, &validate))
end

#splat(name, type, description) {|?| ... } ⇒ Complete

Adds a new Splat to the receiver.

Parameters:

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

Yields:

  • (?)

Yield Parameters:

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

Returns:

Raises:

  • (ArgumentError)

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



41
42
43
# File 'lib/ame-1.0/arguments/undefined.rb', line 41

def splat(name, type, description, &validate)
  Ame::Arguments::Complete.new(@arguments, 'splat', Ame::Splat.new(name, type, description, &validate))
end

#splus(name, type, description) {|?| ... } ⇒ Complete

Adds a new Splus (required splat) to the receiver.

Parameters:

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

Yields:

  • (?)

Yield Parameters:

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

Returns:

Raises:

  • (ArgumentError)

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



51
52
53
# File 'lib/ame-1.0/arguments/undefined.rb', line 51

def splus(name, type, description, &validate)
  Ame::Arguments::Complete.new(@arguments, 'splus', Ame::Splus.new(name, type, description, &validate))
end