Skip to content

Instantly share code, notes, and snippets.

@nilcolor
Forked from nixpulvis/gem-reset
Created September 25, 2013 08:33
Show Gist options
  • Select an option

  • Save nilcolor/6696723 to your computer and use it in GitHub Desktop.

Select an option

Save nilcolor/6696723 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Remove all gems EXCEPT defaults :)
data = `gem list -d`
defaults = []
data.split(/\n\n^(?=\w)/).each do |data|
match = data.match(/(?<name>([^\s]+)) \((?<versions>.*)\)/)
name = match[:name]
versions = match[:versions].split(', ')
if match = data.match(/^.*\((.*)default\): .*$/)
matched_version = match[1].gsub(', ', '')
default_version = matched_version.empty? ? versions[0] : matched_version
versions.delete(default_version)
end
versions.each { |v| system "gem uninstall -Ix #{name} -v #{v}" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment