# File lib/thor/options.rb, line 110
    def parse(args, skip_leading_non_opts = true)
      @args = args
      # start with Thor::Options::Hash pre-filled with defaults
      hash = Hash.new @defaults
      
      @leading_non_opts = []
      if skip_leading_non_opts
        @leading_non_opts << shift until current_is_option? || @args.empty?
      end

      while current_is_option?
        case shift
        when SHORT_SQ_RE
          unshift $1.split('').map { |f| "-#{f}" }
          next
        when EQ_RE, SHORT_NUM
          unshift $2
          switch = $1
        when LONG_RE, SHORT_RE
          switch = $1
        end
        
        switch    = normalize_switch(switch)
        nice_name = undasherize(switch)
        type      = switch_type(switch)
        
        case type
        when :required
          assert_value!(switch)
          raise Error, "cannot pass switch '#{peek}' as an argument" if valid?(peek)
          hash[nice_name] = shift
        when :optional
          hash[nice_name] = peek.nil? || valid?(peek) || shift
        when :boolean
          hash[nice_name] = true
        when :numeric
          assert_value!(switch)
          unless peek =~ NUMERIC and $& == peek
            raise Error, "expected numeric value for '#{switch}'; got #{peek.inspect}"
          end
          hash[nice_name] = $&.index('.') ? shift.to_f : shift.to_i
        end
      end
      
      @trailing_non_opts = @args

      check_required! hash
      hash.freeze
      hash
    end