Defining gem dependencies in single file Ruby scripts

16-Jul-2020 1573
Sometimes I come across cases where I need to write a simple script which uses a gem. The simplest way to go about this is to gem install gem-name and then require 'gem-name' in your script. However, this means that you need to remember to install the gem before running the script.Bundler has an inline gemfile definition feature that lets you define gem dependencies in a single-file Ruby script. To use this feature, require 'bundler/inline' and provide a gemfile block that has the code that you normally put in a Gemfile.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle