Search code examples
rubyrubygemsanti-patterns

Why is it "wrong to require rubygems"?


According to this post, requiring rubygems is an antipattern.

require 'rubygems'

The argument seems to boil down to this:

When I use your library, deploy your app, or run your tests I may not want to use rubygems. When you require 'rubygems' in your code, you remove my ability to make that decision. I cannot unrequire rubygems, but you can not require it in the first place.

But couldn't the same argument be made about any Ruby library that you 'require' when you create and share a library of code with other people?


Solution

  • The main problem with requiring rubygems is that it will cause an error on systems that do not have rubygems installed even if they do have the library that you actually want to require.

    Some people work around that by rescuing LoadError when requiring rubygems, but that's kind of ugly.