Mr eel
RubyGems - Get Your Backwards-compatibility Here
If you’ve upgraded to the latest version of RubyGems you might notice that some older gems break. This is because the #require_gem method is no longer deprecated, it’s been removed entirely. Instead we need to use the #gem method.
That’s cool, but in the meantime we still need #require_gem to work, since it may take awhile for all the various gems we rely on to be updated. Lucky for us it’s easy to do.
unless Object.respond_to? :require_gem
class Object
def require_gem(*args)
gem(*args)
end
end
end
Here we’re just adding the #require_gem method back to the Object class, which palms of it’s arguments to the new #gem method. To make sure it doesn’t break with older versions of RubyGems — an issue when working collaboratively — I’ve wrapped it in a test which checks to see if #require_gem is already declared, in which case we don’t have to add backwards-compatibility.
If you’re using Rails, you can put this bit of code in you environment.rb. Just make sure it comes before any requires for gems.
Comments