This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.

2
Installing and Using a Gem
CodeExpectedActual
require 'cmdparse'
LoadError: no such file to load -- cmdparse
...
LoadError: no such file to load -- cmdparse
	from (irb):1:in `require'
	from (irb):1
require 'rubygems'
require 'cmdparse'
parser = CmdParse::CommandParser.new
...
require 'rubygems/installer'
require 'rubygems/remote_installer'
def install_gem(gem_name)
  if File.file? gem_name:
    Gem::Installer.new(gem_name).install
  else
    Gem::RemoteInstaller.new.install(gem_name)
  end
end
install_gem('cmdparse')
Updating Gem source index for: http://gems.rubyforge.org
Error! (Exception?) Here's stdout:
Errno::EACCES: Permission denied - /usr/lib/ruby/gems/1.8/cache/cmdparse-2.0.1.gem
	from /usr/local/lib/site_ruby/1.8/rubygems/remote_installer.rb:535:in `initialize'
	from /usr/local/lib/site_ruby/1.8/rubygems/remote_installer.rb:535:in `write_gem_to_file'
	from /usr/local/lib/site_ruby/1.8/rubygems/remote_installer.rb:530:in `download_gem'
	from /usr/local/lib/site_ruby/1.8/rubygems/remote_installer.rb:405:in `install'
	from (irb):11:in `install_gem'
	from (irb):14