def search(gem_pattern, platform_only = false)
      version_requirement = nil
      only_platform = false

      # TODO - Remove support and warning for legacy arguments after 2008/11
      unless Gem::Dependency === gem_pattern
        warn "#{Gem.location_of_caller.join ':'}:Warning: Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated, use #find_name"
      end

      case gem_pattern
      when Regexp then
        version_requirement = platform_only || Gem::Requirement.default
      when Gem::Dependency then
        only_platform = platform_only
        version_requirement = gem_pattern.requirement
        gem_pattern = if Regexp === gem_pattern.name then
                        gem_pattern.name
                      elsif gem_pattern.name.empty? then
                        //
                      else
                        /^#{Regexp.escape gem_pattern.name}$/
                      end
      else
        version_requirement = platform_only || Gem::Requirement.default
        gem_pattern = /#{gem_pattern}/i
      end

      unless Gem::Requirement === version_requirement then
        version_requirement = Gem::Requirement.create version_requirement
      end

      specs = all_gems.values.select do |spec|
        spec.name =~ gem_pattern and
          version_requirement.satisfied_by? spec.version
      end

      if only_platform then
        specs = specs.select do |spec|
          Gem::Platform.match spec.platform
        end
      end

      specs.sort_by { |s| s.sort_obj }
    end
def search(gem_pattern, platform_only = false)
      version_requirement = nil
      only_platform = false

      # TODO - Remove support and warning for legacy arguments after 2008/11
      unless Gem::Dependency === gem_pattern
        warn "#{Gem.location_of_caller.join ':'}:Warning: Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated, use #find_name"
      end

      case gem_pattern
      when Regexp then
        version_requirement = platform_only || Gem::Requirement.default
      when Gem::Dependency then
        only_platform = platform_only
        version_requirement = gem_pattern.requirement
        gem_pattern = if Regexp === gem_pattern.name then
                        gem_pattern.name
                      elsif gem_pattern.name.empty? then
                        //
                      else
                        /^#{Regexp.escape gem_pattern.name}$/
                      end
      else
        version_requirement = platform_only || Gem::Requirement.default
        gem_pattern = /#{gem_pattern}/i
      end

      unless Gem::Requirement === version_requirement then
        version_requirement = Gem::Requirement.create version_requirement
      end

      specs = all_gems.values.select do |spec|
        spec.name =~ gem_pattern and
          version_requirement.satisfied_by? spec.version
      end

      if only_platform then
        specs = specs.select do |spec|
          Gem::Platform.match spec.platform
        end
      end

      specs.sort_by { |s| s.sort_obj }
    end
Search for a gem by Gem::Dependency +gem_pattern+.  If +only_platform+
 is true, only gems matching Gem::Platform.local will be returned.  An
 Array of matching Gem::Specification objects is returned.

 For backwards compatibility, a String or Regexp pattern may be passed as
 +gem_pattern+, and a Gem::Requirement for +platform_only+.  This
 behavior is deprecated and will be removed.