From the gemfile man page, I learned there are two ways to import the gems you specified in the Gemfile. The bundle.setup will “setup adds gems to Ruby’s load path” while bundle.require will require all the gems.
What’s the difference between these two methods? In which condition should I use one of them?
Bundler.setupmodifies the LOAD_PATH, so you can do things likerequire 'some_gem'and they will work. It allows you to require gems ‘by hand’. Before Bundler, using Rubygems, you would achieve much of the same effect doingrequire 'rubygems'.Bundler.require(:default)on the other hand actually requires all the gems in the Gemfile (assuming you’re not using groups; otherwise it requires those in the specified groups if you provide arguments). It is a shorthand for a bunch ofrequire 'some_gem'statements.See http://gembundler.com/rationale.html. Note that they say you have to do
require 'bundler/setup'before doingBundler.require, but in practice this usually is not necessary. I almost never useBundler.setup(orrequire 'bundler/setup), because I require all gems viaBundler.require).