Class: Ame::Option

Inherits:
Switch show all
Defined in:
lib/ame-1.0/option.rb

Overview

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

Direct Known Subclasses

Multioption

Instance Attribute Summary

Attributes inherited from Switch

#argument

Attributes inherited from Flag

#default, #description, #long, #short

Instance Method Summary collapse

Methods inherited from Flag

#ignored?, #name, #names, #process

Constructor Details

#initialize(short, long, argument, default, description) {|?| ... } ⇒ Option

Returns a new instance of Option.

Parameters:

  • 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 the type of DEFAULT 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
# File 'lib/ame-1.0/option.rb', line 15

def initialize(short, long, argument, default, description, &validate)
  super short, long, argument, default, nil, description, &validate
end

Instance Method Details

#process_combined(options, arguments, name, remainder) ⇒ [Boolean, '']

Invokes Flag#process with REMAINDER as the explicit argument if it’s non-empty.

Parameters:

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

Returns:

  • ([Boolean, ''])


24
25
26
# File 'lib/ame-1.0/option.rb', line 24

def process_combined(options, arguments, name, remainder)
  [process(options, arguments, name, remainder.empty? ? nil : remainder), '']
end