On this page
End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
Gem::Specification
The Specification class contains the information for a gem. Typically defined in a .gemspec file or a Rakefile, and looks like this:
Gem::Specification.new do |s| s.name = 'example' s.version = '0.1.0' s.licenses = ['MIT'] s.summary = "This is an example!" s.description = "Much longer explanation of the example!" s.authors = ["Ruby Coder"] s.email = '[email protected]' s.files = ["lib/example.rb"] s.homepage = 'https://rubygems.org/gems/example' s.metadata = { "source_code_uri" => "https://github.com/example/example" } end
Starting in RubyGems 2.0, a Specification can hold arbitrary metadata. See metadata for restrictions on the format and size of metadata items you may add to a specification.
Class methods 37
Instance methods 95
The specification version applied to any new Specification instances created. This should be bumped whenever something in the spec format changes.
Specification Version History:
spec ruby
ver ver yyyy-mm-dd description
-1 <0.8.0 pre-spec-version-history
1 0.8.0 2004-08-01 Deprecated "test_suite_file" for "test_files"
"test_file=x" is a shortcut for "test_files=[x]"
2 0.9.5 2007-10-01 Added "required_rubygems_version"
Now forward-compatible with future versions
3 1.3.2 2009-01-03 Added Fixnum validation to specification_version
4 1.9.0 2011-06-07 Added metadata
rubocop:disable Style/MutableConstant
The version number of a specification that does not specify one (i.e. RubyGems 0.7 or earlier).
Sentinel object to represent “not found” stubs
Tracking removed method calls to warn users during build time.
An informal list of changes to the specification. The highest-valued key should be equal to the CURRENT_SPECIFICATION_VERSION.
True when this gemspec has been activated. This attribute is not persisted.
True when this gemspec has been activated. This attribute is not persisted.
The path in the gem for executable scripts. Usually ‘bin’
Usage:
spec.bindir = 'bin'
The certificate chain used to sign this gem. See Gem::Security for details.
Sets the default executable for this gem.
Deprecated: You must now specify the executable name to Gem.bin_path.
A long description of this gem
The description should be more detailed than the summary but not excessively long. A few paragraphs is a recommended length with no examples or formatting.
Usage:
spec.description = <<-EOF Rake is a Make-like program implemented in Ruby. Tasks and dependencies are specified in standard Ruby syntax. EOF
A contact email address (or addresses) for this gem
Usage:
spec.email = '[email protected]' spec.email = ['[email protected]', '[email protected]']
The URL of this gem’s home page
Usage:
spec.homepage = 'https://github.com/ruby/rake'
The metadata holds extra data for this gem that may be useful to other consumers and is settable by gem authors.
Metadata items have the following restrictions:
-
The metadata must be a
Hashobject -
All keys and values must be Strings
-
Keys can be a maximum of 128 bytes and values can be a maximum of 1024 bytes
-
All strings must be UTF-8, no binary data is allowed
You can use metadata to specify links to your gem’s homepage, codebase, documentation, wiki, mailing list, issue tracker and changelog.
s.metadata = {
"bug_tracker_uri" => "https://example.com/user/bestgemever/issues",
"changelog_uri" => "https://example.com/user/bestgemever/CHANGELOG.md",
"documentation_uri" => "https://www.example.info/gems/bestgemever/0.0.1",
"homepage_uri" => "https://bestgemever.example.io",
"mailing_list_uri" => "https://groups.example.com/bestgemever",
"source_code_uri" => "https://example.com/user/bestgemever",
"wiki_uri" => "https://example.com/user/bestgemever/wiki"
"funding_uri" => "https://example.com/donate"
}
These links will be used on your gem’s page on rubygems.org and must pass validation against following regex.
%r{\Ahttps?:\/\/([^\s:@]+:[^\s:@]*@)?[A-Za-z\d\-]+(\.[A-Za-z\d\-]+)+\.?(:\d{1,5})?([\/?]\S*)?\z}
This gem’s name.
Usage:
spec.name = 'rake'
A message that gets displayed after the gem is installed.
Usage:
spec.post_install_message = "Thanks for installing!"
The RubyGems version required by this gem
The version of Ruby required by this gem
Usage:
spec.required_ruby_version = '>= 2.7.0'
The version of RubyGems used to create this gem.
Do not set this, it is set automatically when the gem is packaged.
The key used to sign this gem. See Gem::Security for details.
The Gem::Specification version of this gemspec.
Do not set this, it is set automatically when the gem is packaged.
A short summary of this gem’s description. Displayed in ‘gem list -d`.
The description should be more detailed than the summary.
Usage:
spec.summary = "This is a small summary of my gem"
This gem’s version.
The version string can contain numbers and periods, such as 1.0.0. A gem is a ‘prerelease’ gem if the version has a letter in it, such as 1.0.0.pre.
Usage:
spec.version = '0.4.1'