Last Modified
2016-11-15 11:15:55 -0600
  • rubygems/security
  • rubygems/specification
  • rubygems/user_interaction
  • zlib
  • rubygems/security
  • rubygems/package/digest_io
  • rubygems/package/source
  • rubygems/package/file_source
  • rubygems/package/io_source
  • rubygems/package/old
  • rubygems/package/tar_header
  • rubygems/package/tar_reader
  • rubygems/package/tar_reader/entry
  • rubygems/package/tar_writer


frozen_string_literal: false

Example using a Gem::Package

Builds a .gem file given a Gem::Specification. A .gem file is a tarball which contains a data.tar.gz and metadata.gz, and possibly signatures.

require 'rubygems'
require 'rubygems/package'

spec = do |s|
  s.summary = "Ruby based make-like utility." = 'rake'
  s.version = PKG_VERSION
  s.requirements << 'none'
  s.files = PKG_FILES
  s.description = <<-EOF
Rake is a Make-like program implemented in Ruby. Tasks
and dependencies are specified in standard Ruby syntax.
end spec

Reads a .gem file.

require 'rubygems'
require 'rubygems/package'

the_gem =
the_gem.contents # get the files in the gem
the_gem.extract_files destination_directory # extract the gem into a directory
the_gem.spec # get the spec out of the gem
the_gem.verify # check the gem is OK (contains valid gem specification, contains a not corrupt contents archive)

files are the files in the .gem tar file, not the Ruby files in the gem extract_files and contents automatically call verify

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit

blog comments powered by Disqus