Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Gem::RequestSet::GemDependencyAPI#gem

gem(name)
gem(name, *requirements)
gem(name, *requirements, options)

Specifies a gem dependency with the given name and requirements. You may also supply options following the requirements

options include:

require:

RubyGems does not provide any autorequire features so requires in a gem dependencies file are recorded but ignored.

In bundler the require: option overrides the file to require during Bundler.require. By default the name of the dependency is required in Bundler. A single file or an Array of files may be given.

To disable requiring any file give false:

Example
gem 'rake', require: false
group:

Place the dependencies in the given dependency group. A single group or an Array of groups may be given.

See also group

platform:

Only install the dependency on the given platform. A single platform or an Array of platforms may be given.

See platform for a list of platforms available.

path:

Install this dependency from an unpacked gem in the given directory.

Example
gem 'modified_gem', path: 'vendor/modified_gem'
git:

Install this dependency from a git repository:

gem 'private_gem', git: [email protected]:private_gem.git'
gist:

Install this dependency from the gist ID:

Example
gem 'bang', gist: '1232884'
github:

Install this dependency from a github git repository:

Example
gem 'private_gem', github: 'my_company/private_gem'
submodules:

Set to true to include submodules when fetching the git repository for git:, gist: and github: dependencies.

ref:

Use the given commit name or SHA for git:, gist: and github: dependencies.

branch:

Use the given branch for git:, gist: and github: dependencies.

tag:

Use the given tag for git:, gist: and github: dependencies.

See also .new #gemspec #git also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0