Skip to content

Instantly share code, notes, and snippets.

@zaius
Created May 9, 2012 08:48
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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
@jhirn
Copy link

jhirn commented May 9, 2012

Nice! Works for me for now =)

@danielribeiro
Copy link

NoMethodError: undefined method `activate' for #Gem::Specification:0x1334b3bb8

@zaius
Copy link
Author

zaius commented Jun 19, 2012

@danielribeiro - Which gem are you trying to load? Which version of ruby are you using?

@danielribeiro
Copy link

On both Ree and Ruby 1.8.7 with Bundler version 1.0.21. I get this with all gems, in particular with wirble. The os is mac Lion (Mac OS X Lion 10.7.4 (11E53))

@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