Skip to content

Instantly share code, notes, and snippets.

@avdi
Created April 13, 2016 17:00
Show Gist options
  • Save avdi/892100c9d6485a497eda3aea4ff5e423 to your computer and use it in GitHub Desktop.
Save avdi/892100c9d6485a497eda3aea4ff5e423 to your computer and use it in GitHub Desktop.
Options for "soft" script dependencies
if Gem::Specification.find_all_by_name("clipboard", "~> 1.0").any?
gem "clipboard", "~> 1.0"
require "clipboard"
# ...
end
begin
gem "clipboard", "~> 1.0"
require "clipboard"
# ...
rescue LoadError
# NOOP
end
@drbrain
Copy link

drbrain commented Apr 13, 2016

In this instance the cargo cult built a functional airport.

You may be thinking of:

begin
  require 'rubygems'

  gem 'some_gem'
rescue LoadError, Gem::LoadError
end

require 'some_gem'

Which would allow you to load some_gem regardless of how it was installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment