Bundler Inline

Bundler Inline
Photo by Fahrul Razi / Unsplash

I like Ruby. It's a great language.

I especially like writing shell scripts. There are a ton of super great features built right into the language. The major drawback I see from people is it's not installed everywhere. So, for "public" scripts, use Python. But for most of my work, I'm either writing a script that will only ever run on my machines, or if it's for work, we all have Ruby installed.

The feature that makes it stand out so well is Bundler Inline.

With Bundler Inline, I can install any gem my script might need, and the user running the script doesn't have to do anything but execute the script.

#!/usr/bin/env ruby

require 'bundler/inline'

# Adding `true` will print the standard output of "bundle install"
# I like doing that so it doesn't look like the script is hung while instaling
# large gems or native extensions.
gemfile(true) do
  source 'https://rubygems.org'

  gem 'sinatra', require: false
  gem 'rackup'
  gem 'puma'
end

require 'sinatra/base'

class App < Sinatra::Base
  get '/' do
    'Hello, world!'
  end
end

App.run!

That's it. That's all you need.