Nearly all gems are going to have dependencies upon other libraries that
they require in order to function. These dependencies are explicitly
declared in the gemspec so that when a gem is installed, all of the gems
that are needed to run that gem can automatically be installed with it.
There are two types of gem dependencies, runtime dependencies and
development dependencies.
-
Runtime dependencies are libraries that
your gem needs in order to function. For example, if you built a Rails
extension, you would need to add Rails to the runtime dependencies of
your project.
-
Development dependencies, on the other hand, are gems
that are only needed by people who are going to contribute to the
code of the gem.
- Gems are, by default, installed only with the runtime
dependencies. This avoids cluttering up an environment with development
dependencies if they aren't needed.
Adding dependencies to your gemspec
is extremely simple; all you need
to do is add a line to the gemspec
file for each dependency:
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/my_gem/version', __FILE__)
Gem::Specification.new do |gem|
# ...
gem.add_dependency 'rails'
gem.add_development_dependency 'rspec', '~> 2.7'
end
In addition to specifying the gem name of a dependency, you can also
specify a version of the gem to get even more specific.
Rubygems will default to the latest version if no specific version is required.
git add .
git commit -m "Initial Import"
Casiano Rodriguez León
2015-01-07