class Gem::RequestSet

def install(options, &block) # :yields: request, installer

:yields: request, installer
def install(options, &block) # :yields: request, installer
  if dir = options[:install_dir]
    requests = install_into dir, false, options, &block
    return requests
  end
  @prerelease = options[:prerelease]
  requests = []
  download_queue = Thread::Queue.new
  # Create a thread-safe list of gems to download
  sorted_requests.each do |req|
    download_queue << req
  end
  # Create N threads in a pool, have them download all the gems
  threads = Array.new(Gem.configuration.concurrent_downloads) do
    # When a thread pops this item, it knows to stop running. The symbol
    # is queued here so that there will be one symbol per thread.
    download_queue << :stop
    Thread.new do
      # The pop method will block waiting for items, so the only way
      # to stop a thread from running is to provide a final item that
      # means the thread should stop.
      while req = download_queue.pop
        break if req == :stop
        req.spec.download options unless req.installed?
      end
    end
  end
  # Wait for all the downloads to finish before continuing
  threads.each(&:value)
  # Install requested gems after they have been downloaded
  sorted_requests.each do |req|
    if req.installed?
      req.spec.spec.build_extensions
      if @always_install.none? {|spec| spec == req.spec.spec }
        yield req, nil if block_given?
        next
      end
    end
    spec =
      begin
        req.spec.install options do |installer|
          yield req, installer if block_given?
        end
      rescue Gem::RuntimeRequirementNotMetError => e
        suggestion = "There are no versions of #{req.request} compatible with your Ruby & RubyGems"
        suggestion += ". Maybe try installing an older version of the gem you're looking for?" unless @always_install.include?(req.spec.spec)
        e.suggestion = suggestion
        raise
      end
    requests << spec
  end
  return requests if options[:gemdeps]
  install_hooks requests, options
  requests
end