uzo
uzo

Reputation: 2821

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?

Upvotes: 9

Views: 668

Answers (3)

Andrew Grimm
Andrew Grimm

Reputation: 81691

Rubygems isn't essential to the application, it's just a convenient way of supplying a library. By contrast, the other libraries used are essential to the application.

Upvotes: 0

sepp2k
sepp2k

Reputation: 370465

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.

Upvotes: 9

Matt Briggs
Matt Briggs

Reputation: 42258

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

Upvotes: 10

Related Questions