Incerteza
Incerteza

Reputation: 34944

Using a gem in a pure ruby script (not Rails)

A ruby file:

gem "my-gem", git: "https://github.com/gem123.git", branch: "some-branch"
require "my-gem"

var1 = SomeGem::some_method123
puts var1

It says Could not find 'my-gem' (>= 0) among 330 total gem(s) (Gem::LoadError). Why not? I need a special branch of a gem and don't want to clone the repository.

Upvotes: 13

Views: 5125

Answers (1)

infused
infused

Reputation: 24367

Use bundler. Create a Gemfile along side your ruby script.

In the Gemfile, add:

gem "my-gem", git: "https://github.com/gem123.git", branch: "some-branch"

Make sure bundler is installed:

gem install bundler

And install the required gems:

bundle install

Now just initialize bundler at the top of your script:

require 'rubygems'
require 'bundler/setup'

# require your gems as usual
require 'my-gem'

Upvotes: 32

Related Questions