Module: Temp::Options
- Defined in:
- lib/temp/options.rb
Overview
The Options module contains functions for parsing command line options.
Class Method Summary collapse
-
.parse(args) ⇒ Object
Parses arguments and returns a hash of options.
Class Method Details
.parse(args) ⇒ Object
Parses arguments and returns a hash of options.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/temp/options.rb', line 7 def self.parse(args) = { :args => [] } opt_stop = false args.each do |arg| if arg == '--' opt_stop = true next end if opt_stop [:args] << arg else match = /^(-)?(-no)?((-\w+)+)(=(.+))?$/.match(arg) if match key = match[3].sub('-', '').gsub('-', '_').to_sym if match[5] [key] = match[6] elsif match[2] [key] = false else [key] = true end opt_stop = true if match[1] else [:args] << arg end end end end |