File: package.rb [rubygems: Ruby Standard Library Documentation]
Last Modified
2017-04-01 12:51:22 -0500
  • 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: true

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