PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/option_parser.rb

http://github.com/tgunr/passengerpane
Ruby | 28 lines | 22 code | 3 blank | 3 comment | 9 complexity | 1c7ed999ad294478484d8bebd157c757 MD5 | raw file
 1class OptionParser
 2  def self.parse(argv)
 3    return [{},[]] if argv.empty?
 4    
 5    options  = {}
 6    rest     = []
 7    switch   = nil
 8    
 9    for value in argv
10      # values is a switch
11      if value[0] == 45
12        switch = value.slice((value[1] == 45 ? 2 : 1)..-1)
13        options[switch] = nil
14      else
15        if switch
16          # we encountered a switch so this
17          # value belongs  to  that  switch
18          options[switch] = value
19          switch = nil
20        else
21          rest << value
22        end
23      end
24    end
25    
26    [options, rest]
27  end
28end