module Temp::Options
The Options
module contains functions for parsing command line options.
Public Class Methods
parse(args)
click to toggle source
Parses arguments and returns a hash of options.
# File lib/temp/options.rb, line 7 def self.parse(args) options = { :args => [] } opt_stop = false args.each do |arg| if arg == '--' opt_stop = true next end if opt_stop options[:args] << arg else match = /^(-)?(-no)?((-\w+)+)(=(.+))?$/.match(arg) if match key = match[3].sub('-', '').gsub('-', '_').to_sym if match[5] options[key] = match[6] elsif match[2] options[key] = false else options[key] = true end opt_stop = true if match[1] else options[:args] << arg end end end options end