# File lib/getopt/std.rb, line 45
      def self.getopts(switches)
         args = switches.split(/ */)
         hash = {}
         
         while !ARGV.empty? && ARGV.first =~ /^-(.)(.*)/s
            first, rest = $1, $2
            pos = switches.index(first)

            # Switches on the command line must appear among the characters
            # declared in +switches+.
            raise Error, "invalid option '#{first}'" unless pos

            if args[pos+1] == ":"
               ARGV.shift
               if rest.empty?
                  rest = ARGV.shift

                  # Ensure that switches requiring arguments actually
                  # receive a (non-switch) argument.
                  if rest.nil? || rest.empty?
                     raise Error, "missing argument for '-#{args[pos]}'"
                  end

                  # Do not permit switches that require arguments to be
                  # followed immediately by another switch.
                  temp_args = args.map{ |e| "-#{e}" }

                  if temp_args.include?(rest) || temp_args.include?(rest[1..-1])
                     err = "cannot use switch '#{rest}' as argument "
                     err << "to another switch"
                     raise Error, err
                  end

                  # For non boolean switches, arguments that appear multiple
                  # times are converted to an array (or pushed onto an already
                  # existant array).
                  if hash.has_key?(first)
                     hash[first] = [hash[first], rest].flatten
                  else
                     hash[first] = rest
                  end
               else
                  # Do not permit switches that require arguments to be
                  # followed immediately by another switch.
                  if args.include?(rest) || args.include?(rest[1..-1])
                     err = "cannot use switch '#{rest}' as argument "
                     err += "to another switch"
                     raise Error, err
                  end
               end
            else
               hash[first] = true # Boolean switch
               if rest.empty?
                  ARGV.shift
               else
                  ARGV[0] = "-#{rest}"
               end
            end
         end

         hash
      end