Skip to content

Instantly share code, notes, and snippets.

@mpmuc84
Forked from nixpulvis/gem-reset
Created August 10, 2018 11:50
Show Gist options
  • Select an option

  • Save mpmuc84/a1b42aee7e20ed33982d68af17bf5093 to your computer and use it in GitHub Desktop.

Select an option

Save mpmuc84/a1b42aee7e20ed33982d68af17bf5093 to your computer and use it in GitHub Desktop.

Revisions

  1. Nathan Lilienthal revised this gist Feb 27, 2013. 1 changed file with 3 additions and 7 deletions.
    10 changes: 3 additions & 7 deletions gem-reset
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,14 @@
    #!/usr/bin/env ruby
    # Remove all gems EXCEPT defaults :)

    data = `gem list -d`

    defaults = []
    data.split(/\n\n^(?=\w)/).each do |data|
    `gem list -d`.split(/\n\n^(?=\w)/).each do |data|
    match = data.match(/(?<name>([^\s]+)) \((?<versions>.*)\)/)
    name = match[:name]
    versions = match[:versions].split(', ')

    if match = data.match(/^.*\(([\d\.]*),? ?default\): .*$/)
    next if match[1].empty?
    default_version = match[1] || versions[0]
    versions.delete(default_version)
    next if match[1].empty? # it's the only version if this match is empty
    versions.delete(match[1] || versions[0])
    end

    versions.each { |v| system "gem uninstall -Ix #{name} -v #{v}" }
  2. Nathan Lilienthal revised this gist Feb 27, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gem-reset
    Original file line number Diff line number Diff line change
    @@ -9,9 +9,9 @@ data.split(/\n\n^(?=\w)/).each do |data|
    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
    if match = data.match(/^.*\(([\d\.]*),? ?default\): .*$/)
    next if match[1].empty?
    default_version = match[1] || versions[0]
    versions.delete(default_version)
    end

  3. Nathan Lilienthal created this gist Feb 26, 2013.
    19 changes: 19 additions & 0 deletions gem-reset
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    #!/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