February 02, 2006

rubygems require is lying

RubyGems does some magic with require so you can load gems as though they were regular Ruby libraries. There’s some weirdness, though:

irb(main):001:0> require 'syntaxi'
=> false
irb(main):002:0> Syntaxi
=> Syntaxi
irb(main):003:0> Gem::RubyGemsVersion
=> "0.8.11"

require returned false even though it actually loaded the gem. Of course, I didn’t realize it was loaded, naïvely believing require knew what it was talking about. require_gem "syntaxi" worked, why not this? After some mucking around in rubygems/custom_require.rb, I decided it was at least partly working: Gem::GemPathSearcher#find worked, as did Gem.activate. The only thing left in the overridden require was require__, which is the original Kernel#require.

That’s when I found an email on the rubygems-developers list explaining things. Everything’s fine, ignore that false, move along.

posted at 18:30 -07:00 | ruby | three comments