# File lib/rubygems.rb, line 242
  def self.activate(gem, *version_requirements)
    if version_requirements.last.is_a?(Hash)
      options = version_requirements.pop
    else
      options = {}
    end

    sources = options[:sources] || []

    if version_requirements.empty? then
      version_requirements = Gem::Requirement.default
    end

    unless gem.respond_to?(:name) and
           gem.respond_to?(:version_requirements) then
      gem = Gem::Dependency.new(gem, version_requirements)
    end

    matches = Gem.source_index.find_name(gem.name, gem.version_requirements)
    report_activate_error(gem) if matches.empty?

    if @loaded_specs[gem.name] then
      # This gem is already loaded.  If the currently loaded gem is not in the
      # list of candidate gems, then we have a version conflict.
      existing_spec = @loaded_specs[gem.name]

      unless matches.any? { |spec| spec.version == existing_spec.version } then
         sources_message = sources.map { |spec| spec.full_name }
         stack_message = @loaded_stacks[gem.name].map { |spec| spec.full_name }

         msg = "can't activate #{gem} for #{sources_message.inspect}, "
         msg << "already activated #{existing_spec.full_name} for "
         msg << "#{stack_message.inspect}"

         e = Gem::LoadError.new msg
         e.name = gem.name
         e.version_requirement = gem.version_requirements

         raise e
      end

      return false
    end

    # new load
    spec = matches.last
    return false if spec.loaded?

    spec.loaded = true
    @loaded_specs[spec.name] = spec
    @loaded_stacks[spec.name] = sources.dup

    # Load dependent gems first
    spec.runtime_dependencies.each do |dep_gem|
      activate dep_gem, :sources => [spec, *sources]
    end

    # bin directory must come before library directories
    spec.require_paths.unshift spec.bindir if spec.bindir

    require_paths = spec.require_paths.map do |path|
      File.join spec.full_gem_path, path
    end

    sitelibdir = ConfigMap[:sitelibdir]

    # gem directories must come after -I and ENV['RUBYLIB']
    insert_index = load_path_insert_index

    if insert_index then
      # gem directories must come after -I and ENV['RUBYLIB']
      $LOAD_PATH.insert(insert_index, *require_paths)
    else
      # we are probably testing in core, -I and RUBYLIB don't apply
      $LOAD_PATH.unshift(*require_paths)
    end

    return true
  end