Putting the following snippet in your app:
require 'rubygems'
require 'bundler/setup'
Bundler.require
will properly setup the $LOAD_PATH
and require all gems from your Gemfile.
It is equivalent to manually loading them:
require 'sinatra'
require 'nokogiri'
# ...
See bundler.io
The mustache-sinatra gem depends on sinatra, but does not require it.
When using Bundler.require
(see above), if the Gemfile specifies:
gem 'mustache-sinatra'
gem 'sinatra'
Bundler will load mustache-sinatra
before sinatra
and fail with the error:
Uninitialized constant Sinatra
See Ruby Require Order Problems by yehudakatz.
See also the bundler "Order" spec suite. The suite makes use of two gems, one.rb
depends on but does not require the gem two.rb
, which is standalone.
# Gemfile
gem 'two'
gem 'one'
works, see l.255
# Gemfile
gem 'one'
gem 'two'
fails, see l.295