In almost every Sinatra example I've seen, despite what it does, it always has the following two lines:
require 'rubygems' require 'bundler/setup'
In most examples, removing the 'bundler/setup' require seems to have no breaking effect, so I'm confused about when/where I need to include this.
I hate using things without knowing exactly the reason for it being there, so I was hoping someone could explain why I need both lines and what they do?
Bundler. setup only sets up the load paths so that you can require your dependencies when and wherever you like. Bundler. require sets up the load paths and automatically requires every dependency, saving you from having to manually require each one.
bundle exec allows us to run an executable script in the specific context of the project's bundle. Upon running the above command, bundle exec will run the executable script for rake version specified in project's Gemfile thus avoiding any conflicts with other versions of rake installed system-wide.
Think of bundler as a package management tool. So bundle install command will install all gems to the system that are listed in Gemfile as well as their dependencies. If the gem was not previously installed it will grab it from the gemcutter repo.
It ensures you're loading Gemfile defined gems. Please have a look at the documentation here https://bundler.io/v1.12/bundler_setup.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With