Class: Slop::ArrayOption

Inherits:
Option
  • Object
show all
Defined in:
lib/slop/types.rb

Overview

Collect multiple items into a single Array. Support arguments separated by commas or multiple occurences.

Constant Summary

Constants inherited from Option

Option::DEFAULT_CONFIG

Instance Attribute Summary

Attributes inherited from Option

#block, #config, #count, #desc, #flags, #value

Instance Method Summary collapse

Methods inherited from Option

#ensure_call, #expects_argument?, #finish, #flag, #help?, #initialize, #key, #null?, #required?, #reset, #suppress_errors?, #tail, #tail?, #to_s, #underscore_flags?, #valid?, #validate_type?

Constructor Details

This class inherits a constructor from Slop::Option

Instance Method Details

#call(value) ⇒ Object



95
96
97
98
99
100
101
102
# File 'lib/slop/types.rb', line 95

def call(value)
  @value ||= []
  if delimiter
    @value.concat value.split(delimiter, limit)
  else
    @value << value
  end
end

#default_valueObject



104
105
106
# File 'lib/slop/types.rb', line 104

def default_value
  config[:default] || []
end

#delimiterObject



108
109
110
# File 'lib/slop/types.rb', line 108

def delimiter
  config.fetch(:delimiter, ",")
end

#limitObject



112
113
114
# File 'lib/slop/types.rb', line 112

def limit
  config[:limit] || 0
end