Class: Clin::OptionList

Inherits:
Option
  • Object
show all
Defined in:
lib/clin/option_list.rb

Overview

Option that can be used multiple time in the command line

Instance Attribute Summary

Attributes inherited from Option

#block, #default, #description, #long, #name, #optional_argument, #short, #type

Instance Method Summary collapse

Methods inherited from Option

#==, #argument, #argument=, #argument_optional?, #banner, #cast, #default_argument, #default_long, #default_short, #flag?, #load_default, #long_argument, #option_parser_arguments, parse, #to_a, #trigger

Constructor Details

#initialize(*args) ⇒ OptionList

Returns a new instance of OptionList.



7
8
9
10
11
12
13
14
# File 'lib/clin/option_list.rb', line 7

def initialize(*args)
  super
  if flag?
    self.default = 0
  else
    self.default = []
  end
end

Instance Method Details

#on(value, out) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/clin/option_list.rb', line 16

def on(value, out)
  if flag?
    out[@name] ||= 0
    out[@name] += 1
  else
    out[@name] ||= []
    out[@name] << value
  end
end