Module: ApplixHash

Defined in:
lib/applix/hash.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.parse(arg) ⇒ Object

parse single flag/option into a [key, value] tuple. returns nil on non option/flag arguments.



41
42
43
44
45
46
47
48
# File 'lib/applix/hash.rb', line 41

def self.parse(arg)
  m = /^(-(\w)|--(\w[\w-]+))(([=:])(.+))?$/.match(arg)
  return [nil, arg] unless m # neither option nor flag -> straight arg
  key = (m[2] || m[3]).to_sym
  value = m[6][/(['"]?)(.*)\1$/,2] rescue true
  value = eval(value) if m[5] == ':'
  [key, value]
end