/lib/option_parser.rb
http://github.com/tgunr/passengerpane · Ruby · 28 lines · 22 code · 3 blank · 3 comment · 9 complexity · 1c7ed999ad294478484d8bebd157c757 MD5 · raw file
- class OptionParser
- def self.parse(argv)
- return [{},[]] if argv.empty?
-
- options = {}
- rest = []
- switch = nil
-
- for value in argv
- # values is a switch
- if value[0] == 45
- switch = value.slice((value[1] == 45 ? 2 : 1)..-1)
- options[switch] = nil
- else
- if switch
- # we encountered a switch so this
- # value belongs to that switch
- options[switch] = value
- switch = nil
- else
- rest << value
- end
- end
- end
-
- [options, rest]
- end
- end