Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 670
uzo Avatar asked Sep 16 '09 17:09

uzo


2 Answers

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.

like image 42
sepp2k Avatar answered Oct 24 '22 12:10

sepp2k


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

like image 142
Matt Briggs Avatar answered Oct 24 '22 14:10

Matt Briggs