def initialize(switches)
@defaults = {}
@shorts = {}
@leading_non_opts, @trailing_non_opts = [], []
@switches = switches.inject({}) do |mem, (name, type)|
if name.is_a?(Array)
name, *shorts = name
else
name = name.to_s
shorts = []
end
if name.index('-') == 0
nice_name = undasherize name
else
nice_name = name
name = dasherize name
end
shorts << "-" + nice_name[0,1] if shorts.empty? and nice_name.length > 1
shorts.each { |short| @shorts[short] = name }
case type
when TrueClass then type = :boolean
when String
@defaults[nice_name] = type
type = :optional
when Numeric
@defaults[nice_name] = type
type = :numeric
end
mem[name] = type
mem
end
@shorts.keys.each do |short|
@shorts.delete(short) if @switches.key?(short)
end
end