Class: Ame::Optional

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

Overview

Represents an optional argument to a Method. It has a #default value that will be used if no more arguments are available when it gets called upon to process an argument before the method this argument is associated with gets called.

Instance Attribute Summary collapse

Attributes inherited from Argument

#description, #name

Instance Method Summary collapse

Methods inherited from Argument

#process, #to_s

Constructor Details

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

Returns a new instance of Optional.

Parameters:

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

Yields:

  • (?)

Yield Parameters:

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

Raises:

  • (ArgumentError)

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



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

def initialize(name, default, description, &validate)
  @default = default
  super
end

Instance Attribute Details

#defaultObject? (readonly)

Returns The default value of the receiver.

Returns:

  • (Object, nil)

    The default value of the receiver



22
23
24
# File 'lib/ame-1.0/optional.rb', line 22

def default
  @default
end