instance method
Gem::Uninstaller#uninstall
uninstall
lib/rubygems/uninstaller.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/rubygems/uninstaller.rb, line 94
def uninstall
dependency = Gem::Dependency.new @gem, @version
list = []
specification_record.stubs.each do |spec|
next unless dependency.matches_spec? spec
list << spec
end
if list.empty?
raise Gem::InstallError, "gem #{@gem.inspect} is not installed"
end
default_specs, list = list.partition(&:default_gem?)
warn_cannot_uninstall_default_gems(default_specs - list)
@default_specs_matching_uninstall_params = default_specs.map(&:to_spec)
list, other_repo_specs = list.partition do |spec|
@gem_home == spec.base_dir ||
(@user_install && spec.base_dir == @user_dir)
end
list.sort!
if list.empty?
return unless other_repo_specs.any?
other_repos = other_repo_specs.map(&: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
remove_all list
elsif list.size > 1
gem_names = list.map(&:full_name_with_location)
gem_names << "All versions"
say
_, index = choose_from_list "Select gem to uninstall:", gem_names
if index == list.size
remove_all list
elsif index && index >= 0 && index < list.size
uninstall_gem list[index]
else
say "Error: must enter a number [1-#{list.size + 1}]"
end
else
uninstall_gem list.first
end
end
Performs the uninstall of the gem. This removes the spec, the Gem directory, and the cached .gem file.
See also
#specification_record
#uninstall_gem
#safe_delete
#warn_cannot_uninstall_default_gems
also in
4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0