Skip to content

Instantly share code, notes, and snippets.

@rkh
Created January 24, 2011 09:36
Show Gist options
  • Save rkh/793008 to your computer and use it in GitHub Desktop.
Save rkh/793008 to your computer and use it in GitHub Desktop.
def require_or_install(path, gem_name = path, version = '> 0')
require path
rescue LoadError
require 'rubygems'
require 'rubygems/user_interaction'
require 'rubygems/dependency_installer'
installer = Gem::DependencyInstaller.new
installer.install gem_name, version
Gem.refresh
Gem.activate gem_name, version
require path
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment