class Getopt::Declare::ArrayArg
Class used to handle array arguments
Public Instance Methods
cachecode(ownerflag, itemcount)
click to toggle source
Return string with code to cache array in Getopt::Declare
‘s cache
# File lib/Getopt/Declare.rb, line 394 def cachecode(ownerflag, itemcount) if itemcount > 1 " @cache['#{ownerflag}']['<#{@name}>'] = [] unless @cache['#{ownerflag}']['<#{@name}>'] @cache['#{ownerflag}']['<#{@name}>'] = #{@name}\n" else " @cache['#{ownerflag}'] = #{@name}\n" end end
code(*t)
click to toggle source
Return string with code to process array parameter
# File lib/Getopt/Declare.rb, line 361 def code(*t) if t[0] pos1 = t[0].to_s else pos1 = '0' end code = <<-EOS _VAR_ = %q|<#{@name}>| _VAL_ = nil #{@name} = (@@m[#{pos1}]||'').split(' ').map { |i| i.tr("\\0", " ") } EOS # Handle conversion to proper type c = conversion if c code << " #{@name}.map! { |i| i#{c} }\n" end actions = Getopt::Declare::ScalarArg::stdactions(@type) if actions.size > 0 code << " for _VAL_ in #{@name}\n" for i in actions code << " #{i}\n" end code << " end\n\n" end return code end
matcher(g)
click to toggle source
Create regexp to match array
Calls superclass method
Getopt::Declare::ScalarArg#matcher
# File lib/Getopt/Declare.rb, line 353 def matcher(g) suffix = !g.nil? ? '([\s\0]+)' : '' scalar = super # contains regex to match a scalar element # we match one obligatory element, and one or more optionals ')*' return scalar + '(?:[\s\0]+' + scalar + ')*' + suffix end