gather_dependencies (Gem::DependencyInstaller)

    # File lib/rubygems/dependency_installer.rb, line 122
      def gather_dependencies
        specs = @specs_and_sources.map { |spec,_| spec }

        dependency_list = Gem::DependencyList.new
        dependency_list.add(*specs)

        unless @ignore_dependencies then
          to_do = specs.dup
          seen = {}

          until to_do.empty? do
            spec = to_do.shift
            next if spec.nil? or seen[spec.name]
            seen[spec.name] = true

            deps = spec.runtime_dependencies
            deps |= spec.development_dependencies if @development

            deps.each do |dep|
              results = find_gems_with_sources(dep).reverse

              results.reject! do |dep_spec,|
                to_do.push dep_spec

                @source_index.any? do |_, installed_spec|
                  dep.name == installed_spec.name and
                    dep.version_requirements.satisfied_by? installed_spec.version
                end
              end

              results.each do |dep_spec, source_uri|
                next if seen[dep_spec.name]
                @specs_and_sources << [dep_spec, source_uri]
                dependency_list.add dep_spec
              end
            end
          end
        end

        @gems_to_install = dependency_list.dependency_order.reverse
      end