Class: OptParseBuilder::OptionArgument

Inherits:
Argument
  • Object
show all
Includes:
HasValue
Defined in:
lib/opt_parse_builder/option_argument.rb

Overview

:nodoc:

Constant Summary collapse

DEFAULT_HANDLER =
->(argument, value) { argument.value = value }

Instance Attribute Summary

Attributes included from HasValue

#key, #value

Instance Method Summary collapse

Methods included from HasValue

#init_value, #reset

Methods inherited from Argument

#banner_lines, #footer_lines, #key, #operand_notation, #optional, #required, #reset, #separator_lines, #shift_operand, #to_a, #value, #value=

Constructor Details

#initialize(key, default, on, handler) ⇒ OptionArgument



8
9
10
11
12
# File 'lib/opt_parse_builder/option_argument.rb', line 8

def initialize(key, default, on, handler)
  init_value(key, default)
  @on = on
  @handler = handler || DEFAULT_HANDLER
end

Instance Method Details

#apply_option(op) ⇒ Object



14
15
16
17
18
# File 'lib/opt_parse_builder/option_argument.rb', line 14

def apply_option(op)
  op.on(*edited_on) do |value|
    @handler.call(self, value)
  end
end