views:

294

answers:

2

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?

+7  A: 

If you look at the comments, you will see the author say this

The point I was not trying to make is that rubygems is bad or that people shouldn’t use it. I use rubygems and think it’s a critical piece of Ruby’s success – I just don’t have the line “require 'rubygems'” anywhere in my library’s source code because it’s not necessary or convenient and makes it hard / impossible for other environments (like bundler, rip, GAE, debian, hand rolled, etc) to use the library without rubygems, which is often important.

I actually didn't really agree with him before I read it, now I do

Matt Briggs
+6  A: 

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.

sepp2k