Skip to content

Instantly share code, notes, and snippets.

@alyssais
Last active August 29, 2015 14:27
Show Gist options
  • Save alyssais/92458871bbd691d8d374 to your computer and use it in GitHub Desktop.
Save alyssais/92458871bbd691d8d374 to your computer and use it in GitHub Desktop.
A very hacky way to require gems from outside a bundler environment
require 'shellwords'
def require_external_gem(name)
return require name unless defined? Bundler
dir = Bundler.with_clean_env do
`echo #{name.shellescape} | ruby -e \
'puts Gem::Specification.find_by_name(STDIN.read.chomp).gem_dir'`.chomp
end
$: << File.join(dir, "lib")
require name
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment