Showing posts with label require. Show all posts
Showing posts with label require. Show all posts

09 February, 2008

Hacking Rubygems' #require, #require_gem, #gem

I have some old gems in my latest Rails app, and Rubygems has changed its syntax since those gems were built. The gems have require_gem in them, but the newest version of Rubygems doesn't add that command to Kernel, so you get NoMethodErrors when the gem loads. This simple hack in config/environment.rb will fix it:

# hack rubygem's change to #require:
Kernel.class_eval do
  def require_gem(*args)
    gem *args
  end
end
I have it right before require File.join(File.dirname(__FILE__), 'boot') in case my config/environments/xxx.rb loads an old gem.