Skip to content

Instantly share code, notes, and snippets.

@zaius
Created May 9, 2012 08:48
Show Gist options
  • Save zaius/2643079 to your computer and use it in GitHub Desktop.
Save zaius/2643079 to your computer and use it in GitHub Desktop.
Allow requiring of global gems from outside of the Gemfile
# Include this in your .irbrc
def unbundled_require(gem)
if defined?(::Bundler)
spec_path = Dir.glob("#{Gem.dir}/specifications/#{gem}-*.gemspec").last
if spec_path.nil?
warn "Couldn't find #{gem}"
return
end
spec = Gem::Specification.load spec_path
spec.activate
end
begin
require gem
yield if block_given?
rescue Exception => err
warn "Couldn't load #{gem}: #{err}"
end
end
# Then use like this
unbundled_require 'wirb' do
Wirb.start
end
@zaius
Copy link
Author

zaius commented Jun 19, 2012

Ah ok. I've well and truly given up on 1.8, so this will probably only work on 1.9. But let me know if you get it working!

@stormsilver
Copy link

I added a fix à la the Gemfile for requiring a gem with a different name than the gem itself: https://gist.github.com/3894925

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment