uninstall()
  public
  
    
    
Performs the uninstall of the
gem.  This removes the spec, the Gem directory, and
the cached .gem file.
   
  
    Show source    
    
      
  def uninstall
    dependency = Gem::Dependency.new @gem, @version
    list = []
    dirs =
      Gem::Specification.dirs +
      [Gem::Specification.default_specifications_dir]
    Gem::Specification.each_spec dirs do |spec|
      next unless dependency.matches_spec? spec
      list << spec
    end
    default_specs, list = list.partition do |spec|
      spec.default_gem?
    end
    list, other_repo_specs = list.partition do |spec|
      @gem_home == spec.base_dir or
        (@user_install and spec.base_dir == Gem.user_dir)
    end
    list.sort!
    if list.empty? then
      if other_repo_specs.empty?
        if default_specs.empty?
          raise Gem::InstallError, "gem #{@gem.inspect} is not installed"
        else
          message =
            "gem #{@gem.inspect} cannot be uninstalled " +
            "because it is a default gem"
          raise Gem::InstallError, message
        end
      end
      other_repos = other_repo_specs.map { |spec| spec.base_dir }.uniq
      message = ["#{@gem} is not installed in GEM_HOME, try:"]
      message.concat other_repos.map { |repo|
        "\tgem uninstall -i #{repo} #{@gem}"
      }
      raise Gem::InstallError, message.join("\n")
    elsif @force_all then
      remove_all list
    elsif list.size > 1 then
      gem_names = list.map { |gem| gem.full_name }
      gem_names << "All versions"
      say
      _, index = choose_from_list "Select gem to uninstall:", gem_names
      if index == list.size then
        remove_all list
      elsif index >= 0 && index < list.size then
        uninstall_gem list[index]
      else
        say "Error: must enter a number [1-#{list.size+1}]"
      end
    else
      uninstall_gem list.first
    end
  end