Class: Ame::Switch

Inherits:
Flag
  • Object
show all
Defined in:
lib/ame-1.0/switch.rb

Overview

Represents an option to a Method that takes an optional argument. If an explicit (‘=’-separated) argument is given, it’ll be used, otherwise a default value, which differs from the default value used if the option isn’t given at all, will be used.

Direct Known Subclasses

Option

Instance Attribute Summary collapse

Attributes inherited from Flag

#default, #description, #long, #short

Instance Method Summary collapse

Methods inherited from Flag

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

Constructor Details

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

Returns a new instance of Switch.

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 ARGUMENT_DEFAULT or, if ARGUMENT_DEFAULT is nil, DEFAULT isn’t one that Ame knows how to parse

  • (ArgumentError)

    If SHORT and LONG are #strip#empty?

  • (ArgumentError)

    If SHORT#strip#length > 1



20
21
22
23
24
25
# File 'lib/ame-1.0/switch.rb', line 20

def initialize(short, long, argument, default, argument_default, description, &validate)
  @argument = argument.upcase
  @type = Ame::Types[[argument_default, default, String].reject(&:nil?).first]
  @argument_default = @type.respond_to?(:default) ? @type.default : argument_default
  super short, long, default, description, &validate
end

Instance Attribute Details

#argumentString (readonly)

Returns The name of the argument to the receiver.

Returns:

  • (String)

    The name of the argument to the receiver



28
29
30
# File 'lib/ame-1.0/switch.rb', line 28

def argument
  @argument
end