Skip to content

Instantly share code, notes, and snippets.

@addame
Created December 26, 2010 03:08
Show Gist options
  • Save addame/755184 to your computer and use it in GitHub Desktop.
Save addame/755184 to your computer and use it in GitHub Desktop.
# a dirty method to write all installed gems in a file as commands ready ... for installation
# useful when upgrading (even if rvm is a killer ;-) )
require "date"
def list_installed_gems
gems = `gem list`
all_gems = gems.chomp!.split(/\n/)
@f = File.open("gem_list_install_#{Date.parse(Time.now.to_s).to_s}.sh", "w")
# create install commande
all_gems.each do |gem|
gem =~ /(\S+)\s\((.+)\)/im
@gem_name = $1
# save them into arrays
@gem_versions = $2.split(/,/)
# print the commands
@gem_versions.each do |gem_version|
#puts "gem install #{@gem_name} --version=#{gem_version.strip} --no-ri --no-rdoc \n"
@f.write("gem install #{@gem_name} --version=#{gem_version.strip} --no-ri --no-rdoc \n")
end
end
@f.close
end
list_installed_gems
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment