What's the difference between require 'cool_lib'
and gem 'cool_lib'
?
views:
98answers:
1
+3
A:
gem
gives you more options as to which exact gem you load: see here for plenty of details. In this example, there's no effective difference.
I'd recommend using require
unless you specifically need the power of gem
- it seems to be what most people use.
Peter
2010-01-30 08:25:24
Thank you very much for your explanation. I really appreciate it.
TK
2010-01-30 08:55:54
One difference is that if you are sharing your code with someone who doesn't use rubygems, the 'require' form will still work for them (as long as they have manually installed cool_lib in the include path).
invariant
2010-01-30 09:37:36
Good answer, but don't "require 'rubygems'". See: http://www.rubyinside.com/why-using-require-rubygems-is-wrong-1478.html .
Wayne Conrad
2010-01-30 15:39:24
@Wayne: I've removed the `require 'rubygems'`; fair point. I mainly said it since it's an easy 'gotcha' for new players.
Peter
2010-01-30 19:47:35
@Peter, Fair point. It was my gotcha until just recently.
Wayne Conrad
2010-01-30 20:23:59
Maybe this should be a separate question, but if `require 'rubygems'` is wrong, is it wrong to use `gem`?
Andrew Grimm
2010-01-31 22:02:07