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.
RoR Gems make development with Rails worthwhile. Gems in Rails are libraries that allow any Ruby on Rails developer to add functionalities without writing code. You can also call Ruby on Rails gems as plugins for adding features. A Ruby gem enables adding features without creating the code again and again.
Ruby comes with RubyGems by default since version 1.9, previous Ruby versions require RubyGems to be installed by hand. Some other libraries are released as archived (.
Gems can be used to extend or modify functionality in Ruby applications. Commonly they're used to distribute reusable functionality that is shared with other Rubyists for use in their applications and libraries. Some gems provide command line utilities to help automate tasks and speed up your work.
A Gemfile describes the gem dependencies required to execute associated Ruby code. Place the Gemfile in the root of the directory containing the associated code. For instance, in a Rails application, place the Gemfile in the same directory as the Rakefile .
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'
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