Skip to content

Instantly share code, notes, and snippets.

@adamjmurray
Created July 21, 2012 03:18
Show Gist options
  • Select an option

  • Save adamjmurray/3154437 to your computer and use it in GitHub Desktop.

Select an option

Save adamjmurray/3154437 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Jul 21, 2012.
    38 changes: 38 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    # Environment, set GEM_HOME & GEM_PATH. For example, we can launch JRuby like this:
    # GEM_HOME=/Users/amurray/tmp/gems/ GEM_PATH=/Users/amurray/tmp/gems java -jar ~/Downloads/jruby-complete-1.7.0.preview1.jar -S irb

    # =====================
    # LISTING gems
    puts Gem::Specification.find_all.to_s
    puts Gem::Specification.find_all.map{|spec| "#{spec.name} (#{spec.version})" }

    # =====================
    # USING (a specific version of) gems
    gem 'rake', '0.9.0'
    require 'rake'

    # ====================
    # INSTALLING gems
    require 'rubygems/commands/install_command'
    cmd = Gem::Commands::InstallCommand.new
    cmd.handle_options ["--no-ri", "--no-rdoc", 'rake', '--version', '0.9'] # or omit --version and the following option to install the latest

    begin
    cmd.execute
    rescue Gem::SystemExitException => e
    puts "DONE: #{e.exit_code}"
    end

    # =====================
    # UNINSTALLING gems
    require 'rubygems/commands/uninstall_command'
    cmd = Gem::Commands::UninstallCommand.new
    cmd.handle_options ['-x', '-I', 'jasmine'] # -x removes executables without prompting. -I ignores dependecies. Can also uninstall specific versions...
    cmd.execute

    # =====================
    # UPDATING a gem to latest version
    require 'rubygems/commands/update_command'
    cmd = Gem::Commands::UpdateCommand.new
    cmd.handle_options ['--no-rdoc', '--no-ri', 'rake']
    cmd.execute