Module Gem
In: lib/rubygems/defaults.rb
lib/rubygems/gem_openssl.rb
lib/rubygems/test_case.rb
lib/rubygems.rb

RubyGems is the Ruby standard for publishing and managing third party libraries.

For user documentation, see:

For gem developer documentation see:

Further RubyGems documentation can be found at:

RubyGems Plugins

As of RubyGems 1.3.2, RubyGems will load plugins installed in gems or $LOAD_PATH. Plugins must be named ‘rubygems_plugin’ (.rb, .so, etc) and placed at the root of your gem‘s require_path. Plugins are discovered via Gem::find_files then loaded. Take care when implementing a plugin as your plugin file may be loaded multiple times if multiple versions of your gem are installed.

For an example plugin, see the graph gem which adds a `gem graph` command.

RubyGems Defaults, Packaging

RubyGems defaults are stored in rubygems/defaults.rb. If you‘re packaging RubyGems or implementing Ruby you can change RubyGems’ defaults.

For RubyGems packagers, provide lib/rubygems/operating_system.rb and override any defaults from lib/rubygems/defaults.rb.

For Ruby implementers, provide lib/rubygems/#{RUBY_ENGINE}.rb and override any defaults from lib/rubygems/defaults.rb.

If you need RubyGems to perform extra work on install or uninstall, your defaults override file can set pre and post install and uninstall hooks. See Gem::pre_install, Gem::pre_uninstall, Gem::post_install, Gem::post_uninstall.

Bugs

You can submit bugs to the RubyGems bug tracker on RubyForge

Credits

RubyGems is currently maintained by Eric Hodel.

RubyGems was originally developed at RubyConf 2003 by:

  • Rich Kilmer — rich(at)infoether.com
  • Chad Fowler — chad(at)chadfowler.com
  • David Black — dblack(at)wobblini.net
  • Paul Brannan — paul(at)atdesk.com
  • Jim Weirch — jim(at)weirichhouse.org

Contributors:

  • Gavin Sinclair — gsinclair(at)soyabean.com.au
  • George Marrows — george.marrows(at)ntlworld.com
  • Dick Davies — rasputnik(at)hellooperator.net
  • Mauricio Fernandez — batsman.geo(at)yahoo.com
  • Simon Strandgaard — neoneye(at)adslhome.dk
  • Dave Glasser — glasser(at)mit.edu
  • Paul Duncan — pabs(at)pablotron.org
  • Ville Aine — vaine(at)cs.helsinki.fi
  • Eric Hodel — drbrain(at)segment7.net
  • Daniel Berger — djberg96(at)gmail.com
  • Phil Hagelberg — technomancy(at)gmail.com
  • Ryan Davis — ryand-ruby(at)zenspider.com

(If your name is missing, PLEASE let us know!)

Thanks!

-The RubyGems Team

Methods

Classes and Modules

Module Gem::Commands
Module Gem::DefaultUserInteraction
Module Gem::Ext
Module Gem::GemcutterUtilities
Module Gem::InstallUpdateOptions
Module Gem::LocalRemoteOptions
Module Gem::Package
Module Gem::RequirePathsBuilder
Module Gem::Text
Module Gem::UserInteraction
Module Gem::VersionOption
Class Gem::Builder
Class Gem::Command
Class Gem::CommandLineError
Class Gem::CommandManager
Class Gem::ConfigFile
Class Gem::ConsoleUI
Class Gem::Dependency
Class Gem::DependencyError
Class Gem::DependencyInstaller
Class Gem::DependencyList
Class Gem::DependencyRemovalException
Class Gem::DocManager
Class Gem::DocumentError
Class Gem::EndOfYAMLException
Class Gem::ErrorReason
Class Gem::Exception
Class Gem::FakeFetcher
Class Gem::FileOperations
Class Gem::FilePermissionError
Class Gem::Format
Class Gem::FormatException
Class Gem::GemNotFoundException
Class Gem::GemNotInHomeException
Class Gem::GemPathSearcher
Class Gem::GemRunner
Class Gem::Indexer
Class Gem::InstallError
Class Gem::Installer
Class Gem::InstallerTestCase
Class Gem::InvalidSpecificationException
Class Gem::LoadError
Class Gem::MockGemUi
Class Gem::OldFormat
Class Gem::OperationNotSupportedError
Class Gem::PackageTask
Class Gem::Platform
Class Gem::PlatformMismatch
Class Gem::RemoteError
Class Gem::RemoteFetcher
Class Gem::RemoteInstallationCancelled
Class Gem::RemoteInstallationSkipped
Class Gem::RemoteSourceException
Class Gem::Requirement
Class Gem::Server
Class Gem::SilentUI
Class Gem::SourceIndex
Class Gem::SpecFetcher
Class Gem::Specification
Class Gem::StreamUI
Class Gem::SystemExitException
Class Gem::TestCase
Class Gem::Uninstaller
Class Gem::Validator
Class Gem::VerificationError
Class Gem::Version

Constants

QUICKLOADER_SUCKAGE = RUBY_VERSION =~ /^1\.9\.1/
GEM_PRELUDE_SUCKAGE = RUBY_VERSION =~ /^1\.9\.2/
VERSION = '1.7.2'
WIN_PATTERNS = [ /bccwin/i, /cygwin/i, /djgpp/i, /mingw/i, /mswin/i, /wince/i, ]   An Array of Regexps that match windows ruby platforms.
MARSHAL_SPEC_DIR = "quick/Marshal.#{Gem.marshal_version}/"   Location of Marshal quick gemspecs on remote repositories

Attributes

loaded_specs  [R]  Hash of loaded Gem::Specification keyed by name
post_build_hooks  [R]  The list of hooks to be run before Gem::Install#install finishes installation
post_install_hooks  [R]  The list of hooks to be run before Gem::Install#install does any work
post_uninstall_hooks  [R]  The list of hooks to be run before Gem::Uninstall#uninstall does any work
pre_install_hooks  [R]  The list of hooks to be run after Gem::Install#install is finished
pre_uninstall_hooks  [R]  The list of hooks to be run after Gem::Uninstall#uninstall is finished
ssl_available  [W]  Is SSL available?

Public Class methods

Activates an installed gem matching dep. The gem must satisfy requirements.

Returns true if the gem is activated, false if it is already loaded, or an exception otherwise.

Gem#activate adds the library paths in dep to $LOAD_PATH. Before a Gem is activated its required Gems are activated. If the version information is omitted, the highest version Gem of the supplied name is loaded. If a Gem is not found that meets the version requirements or a required Gem is not found, a Gem::LoadError is raised.

More information on version requirements can be found in the Gem::Requirement and Gem::Version documentation.

[Source]

     # File lib/rubygems.rb, line 235
235:   def self.activate(dep, *requirements)
236:     activate_dep dep, *requirements
237:   end

[Source]

     # File lib/rubygems.rb, line 239
239:   def self.activate_dep dep, *requirements
240:     requirements = Gem::Requirement.default if requirements.empty?
241:     dep = Gem::Dependency.new(dep, requirements) unless Gem::Dependency === dep
242: 
243:     matches = Gem.source_index.search dep, true
244:     report_activate_error(dep) if matches.empty?
245: 
246:     existing_spec = @loaded_specs[dep.name]
247: 
248:     # TODO: move this to Dependency
249:     if existing_spec then
250:       # This gem is already loaded.  If the currently loaded gem is not in the
251:       # list of candidate gems, then we have a version conflict.
252: 
253:       # TODO: unless dep.matches_spec? existing_spec then
254:       unless matches.any? { |spec| spec.version == existing_spec.version } then
255:         msg = "can't activate #{dep}, "
256:         msg << "already activated #{existing_spec.full_name}"
257: 
258:         e = Gem::LoadError.new msg
259:         e.name = dep.name
260:         e.requirement = dep.requirement
261: 
262:         raise e
263:       end
264: 
265:       return false
266:     end
267: 
268:     # TODO: this + spec.conflicts hint that activation is still dumb
269:     spec = matches.last
270: 
271:     activate_spec spec
272:   end

[Source]

     # File lib/rubygems.rb, line 274
274:   def self.activate_spec spec
275:     existing_spec = @loaded_specs[spec.name]
276: 
277:     # TODO: move this to Specification
278:     if existing_spec then
279:       if spec.version != existing_spec.version then
280:         # This gem is already loaded.  If the currently loaded gem is not in the
281:         # list of candidate gems, then we have a version conflict.
282: 
283:         msg = "can't activate #{dep}, "
284:         msg << "already activated #{existing_spec.full_name}"
285: 
286:         e = Gem::LoadError.new msg
287:         e.name = dep.name
288:         e.requirement = dep.requirement
289: 
290:         raise e
291:       end
292: 
293:       return false
294:     end
295: 
296:     conf = spec.conflicts
297: 
298:     unless conf.empty? then
299:       why = conf.map { |act,con|
300:         "#{act.full_name} conflicts with #{con.join(", ")}"
301:       }.join ", "
302: 
303:       # TODO: improve message by saying who activated `con`
304: 
305:       raise LoadError, "Unable to activate #{spec.full_name}, because #{why}"
306:     end
307: 
308:     spec.loaded = true
309:     @loaded_specs[spec.name]  = spec
310: 
311:     spec.runtime_dependencies.each do |spec_dep|
312:       next if Gem.loaded_specs.include? spec_dep.name
313:       specs = Gem.source_index.search spec_dep, true
314: 
315:       if specs.size == 1 then
316:         self.activate spec_dep
317:       else
318:         name = spec_dep.name
319:         unresolved_deps[name] = unresolved_deps[name].merge spec_dep
320:       end
321:     end
322: 
323:     unresolved_deps.delete spec.name
324: 
325:     require_paths = spec.require_paths.map do |path|
326:       File.join spec.full_gem_path, path
327:     end
328: 
329:     # gem directories must come after -I and ENV['RUBYLIB']
330:     insert_index = load_path_insert_index
331: 
332:     if insert_index then
333:       # gem directories must come after -I and ENV['RUBYLIB']
334:       $LOAD_PATH.insert(insert_index, *require_paths)
335:     else
336:       # we are probably testing in core, -I and RUBYLIB don't apply
337:       $LOAD_PATH.unshift(*require_paths)
338:     end
339: 
340:     return true
341:   end

An Array of all possible load paths for all versions of all gems in the Gem installation.

[Source]

     # File lib/rubygems.rb, line 351
351:   def self.all_load_paths
352:     result = []
353: 
354:     Gem.path.each do |gemdir|
355:       each_load_path all_partials(gemdir) do |load_path|
356:         result << load_path
357:       end
358:     end
359: 
360:     result
361:   end

See if a given gem is available.

[Source]

     # File lib/rubygems.rb, line 375
375:   def self.available?(gem, *requirements)
376:     requirements = Gem::Requirement.default if requirements.empty?
377: 
378:     unless gem.respond_to?(:name) and
379:            gem.respond_to?(:requirement) then
380:       gem = Gem::Dependency.new gem, requirements
381:     end
382: 
383:     !Gem.source_index.search(gem).empty?
384:   end

Find the full path to the executable for gem name. If the exec_name is not given, the gem‘s default_executable is chosen, otherwise the specified executable‘s path is returned. requirements allows you to specify specific gem versions.

[Source]

     # File lib/rubygems.rb, line 392
392:   def self.bin_path(name, exec_name = nil, *requirements)
393:     raise ArgumentError, "you must supply exec_name" unless exec_name
394: 
395:     requirements = Gem::Requirement.default if
396:       requirements.empty?
397:     specs = Gem.source_index.find_name(name, requirements)
398: 
399:     raise Gem::GemNotFoundException,
400:           "can't find gem #{name} (#{requirements})" if specs.empty?
401: 
402:     specs = specs.find_all do |spec|
403:       spec.executables.include?(exec_name)
404:     end if exec_name
405: 
406:     unless spec = specs.last
407:       msg = "can't find gem #{name} (#{requirements}) with executable #{exec_name}"
408:       raise Gem::GemNotFoundException, msg
409:     end
410: 
411:     exec_name ||= spec.default_executable
412: 
413:     unless exec_name
414:       msg = "no default executable for #{spec.full_name} and none given"
415:       raise Gem::Exception, msg
416:     end
417: 
418:     File.join(spec.full_gem_path, spec.bindir, exec_name)
419:   end

The mode needed to read a file as straight binary.

[Source]

     # File lib/rubygems.rb, line 424
424:   def self.binary_mode
425:     'rb'
426:   end

The path where gem executables are to be installed.

[Source]

     # File lib/rubygems.rb, line 431
431:   def self.bindir(install_dir=Gem.dir)
432:     return File.join(install_dir, 'bin') unless
433:       install_dir.to_s == Gem.default_dir
434:     Gem.default_bindir
435:   end

Get the appropriate cache path.

Pass a string to use a different base path, or nil/false (default) for Gem.dir.

[Source]

     # File lib/rubygems.rb, line 771
771:   def self.cache_dir(custom_dir=false)
772:     File.join(custom_dir ? custom_dir : Gem.dir, 'cache')
773:   end

Given a gem path, find the gem in cache.

Pass a string as the second argument to use a different base path, or nil/false (default) for Gem.dir.

[Source]

     # File lib/rubygems.rb, line 781
781:   def self.cache_gem(filename, user_dir=false)
782:     File.join(cache_dir(user_dir), filename)
783:   end

Reset the dir and path values. The next time dir or path is requested, the values will be calculated from scratch. This is mainly used by the unit tests to provide test isolation.

[Source]

     # File lib/rubygems.rb, line 442
442:   def self.clear_paths
443:     @gem_home = nil
444:     @gem_path = nil
445:     @user_home = nil
446: 
447:     @@source_index = nil
448: 
449:     @searcher = nil
450:   end

The path to standard location of the user‘s .gemrc file.

[Source]

     # File lib/rubygems.rb, line 455
455:   def self.config_file
456:     File.join Gem.user_home, '.gemrc'
457:   end

The standard configuration object for gems.

[Source]

     # File lib/rubygems.rb, line 462
462:   def self.configuration
463:     @configuration ||= Gem::ConfigFile.new []
464:   end

Use the given configuration object (which implements the ConfigFile protocol) as the standard configuration object.

[Source]

     # File lib/rubygems.rb, line 470
470:   def self.configuration=(config)
471:     @configuration = config
472:   end

The path the the data directory specified by the gem name. If the package is not available as a gem, return nil.

[Source]

     # File lib/rubygems.rb, line 478
478:   def self.datadir(gem_name)
479:     spec = @loaded_specs[gem_name]
480:     return nil if spec.nil?
481:     File.join(spec.full_gem_path, 'data', gem_name)
482:   end

The default directory for binaries

[Source]

    # File lib/rubygems/defaults.rb, line 67
67:   def self.default_bindir
68:     if defined? RUBY_FRAMEWORK_VERSION then # mac framework support
69:       '/usr/bin'
70:     else # generic install
71:       ConfigMap[:bindir]
72:     end
73:   end

Default home directory path to be used if an alternate value is not specified in the environment

[Source]

    # File lib/rubygems/defaults.rb, line 19
19:   def self.default_dir
20:     if defined? RUBY_FRAMEWORK_VERSION then
21:       File.join File.dirname(ConfigMap[:sitedir]), 'Gems',
22:                 ConfigMap[:ruby_version]
23:     elsif ConfigMap[:rubylibprefix] then
24:       File.join(ConfigMap[:rubylibprefix], 'gems',
25:                 ConfigMap[:ruby_version])
26:     else
27:       File.join(ConfigMap[:libdir], ruby_engine, 'gems',
28:                 ConfigMap[:ruby_version])
29:     end
30:   end

Deduce Ruby‘s —program-prefix and —program-suffix from its install name

[Source]

    # File lib/rubygems/defaults.rb, line 53
53:   def self.default_exec_format
54:     exec_format = ConfigMap[:ruby_install_name].sub('ruby', '%s') rescue '%s'
55: 
56:     unless exec_format =~ /%s/ then
57:       raise Gem::Exception,
58:         "[BUG] invalid exec_format #{exec_format.inspect}, no %s"
59:     end
60: 
61:     exec_format
62:   end

Default gem load path

[Source]

    # File lib/rubygems/defaults.rb, line 42
42:   def self.default_path
43:     if File.exist? Gem.user_home then
44:       [user_dir, default_dir]
45:     else
46:       [default_dir]
47:     end
48:   end

An Array of the default sources that come with RubyGems

[Source]

    # File lib/rubygems/defaults.rb, line 11
11:   def self.default_sources
12:     %w[http://rubygems.org/]
13:   end

The default system-wide source info cache directory

[Source]

    # File lib/rubygems/defaults.rb, line 78
78:   def self.default_system_source_cache_dir
79:     File.join Gem.dir, 'source_cache'
80:   end

The default user-specific source info cache directory

[Source]

    # File lib/rubygems/defaults.rb, line 85
85:   def self.default_user_source_cache_dir
86:     File.join Gem.user_home, '.gem', 'source_cache'
87:   end

A Zlib::Deflate.deflate wrapper

[Source]

     # File lib/rubygems.rb, line 487
487:   def self.deflate(data)
488:     require 'zlib'
489:     Zlib::Deflate.deflate data
490:   end

The path where gems are to be installed.

[Source]

     # File lib/rubygems.rb, line 495
495:   def self.dir
496:     @gem_home ||= nil
497:     set_home(ENV['GEM_HOME'] || default_dir) unless @gem_home
498:     @gem_home
499:   end

Quietly ensure the named Gem directory contains all the proper subdirectories. If we can‘t create a directory due to a permission problem, then we will silently continue.

[Source]

     # File lib/rubygems.rb, line 528
528:   def self.ensure_gem_subdirectories(gemdir)
529:     require 'fileutils'
530: 
531:     Gem::DIRECTORIES.each do |filename|
532:       fn = File.join gemdir, filename
533:       FileUtils.mkdir_p fn rescue nil unless File.exist? fn
534:     end
535:   end

Ensure that SSL is available. Throw an exception if it is not.

[Source]

    # File lib/rubygems/gem_openssl.rb, line 31
31:     def ensure_ssl_available
32:       unless ssl_available?
33:         raise Gem::Exception, "SSL is not installed on this system"
34:       end
35:     end

Returns a list of paths matching glob that can be used by a gem to pick up features from other gems. For example:

  Gem.find_files('rdoc/discover').each do |path| load path end

if check_load_path is true (the default), then find_files also searches $LOAD_PATH for files as well as gems.

Note that find_files will return all files even if they are from different versions of the same gem.

[Source]

     # File lib/rubygems.rb, line 549
549:   def self.find_files(glob, check_load_path=true)
550:     files = []
551: 
552:     if check_load_path
553:       files = $LOAD_PATH.map { |load_path|
554:         Dir["#{File.expand_path glob, load_path}#{Gem.suffix_pattern}"]
555:       }.flatten.select { |file| File.file? file.untaint }
556:     end
557: 
558:     specs = searcher.find_all glob
559: 
560:     specs.each do |spec|
561:       files.concat searcher.matching_files(spec, glob)
562:     end
563: 
564:     # $LOAD_PATH might contain duplicate entries or reference
565:     # the spec dirs directly, so we prune.
566:     files.uniq! if check_load_path
567: 
568:     return files
569:   end

Zlib::GzipReader wrapper that unzips data.

[Source]

     # File lib/rubygems.rb, line 609
609:   def self.gunzip(data)
610:     # TODO: move to utils
611:     require 'stringio'
612:     require 'zlib'
613:     data = StringIO.new data
614: 
615:     Zlib::GzipReader.new(data).read
616:   end

Zlib::GzipWriter wrapper that zips data.

[Source]

     # File lib/rubygems.rb, line 621
621:   def self.gzip(data)
622:     # TODO: move to utils
623:     require 'stringio'
624:     require 'zlib'
625:     zipped = StringIO.new
626: 
627:     Zlib::GzipWriter.wrap zipped do |io| io.write data end
628: 
629:     zipped.string
630:   end

Get the default RubyGems API host. This is normally rubygems.org.

[Source]

     # File lib/rubygems.rb, line 645
645:   def self.host
646:     # TODO: move to utils
647:     @host ||= "https://rubygems.org"
648:   end

Set the default RubyGems API host.

[Source]

     # File lib/rubygems.rb, line 652
652:   def self.host= host
653:     # TODO: move to utils
654:     @host = host
655:   end

A Zlib::Inflate#inflate wrapper

[Source]

     # File lib/rubygems.rb, line 635
635:   def self.inflate(data)
636:     # TODO: move to utils
637:     require 'zlib'
638:     Zlib::Inflate.inflate data
639:   end

Return a list of all possible load paths for the latest version for all gems in the Gem installation.

[Source]

     # File lib/rubygems.rb, line 661
661:   def self.latest_load_paths
662:     result = []
663: 
664:     Gem.path.each do |gemdir|
665:       each_load_path(latest_partials(gemdir)) do |load_path|
666:         result << load_path
667:       end
668:     end
669: 
670:     result
671:   end

[Source]

     # File lib/rubygems.rb, line 986
986:   def self.latest_rubygems_version
987:     latest_version_for "rubygems-update"
988:   end

[Source]

     # File lib/rubygems.rb, line 967
967:   def self.latest_spec_for name
968:     dependency  = Gem::Dependency.new name
969:     fetcher     = Gem::SpecFetcher.fetcher
970:     spec_tuples = fetcher.find_matching dependency
971: 
972:     match = spec_tuples.select { |(n, _, p), _|
973:       n == name and Gem::Platform.match p
974:     }.sort_by { |(_, version, _), _|
975:       version
976:     }.last
977: 
978:     match and fetcher.fetch_spec(*match)
979:   end

[Source]

     # File lib/rubygems.rb, line 981
981:   def self.latest_version_for name
982:     spec = latest_spec_for name
983:     spec and spec.version
984:   end

Find all ‘rubygems_plugin’ files in $LOAD_PATH and load them

[Source]

      # File lib/rubygems.rb, line 1191
1191:   def self.load_env_plugins
1192:     path = "rubygems_plugin"
1193: 
1194:     files = []
1195:     $LOAD_PATH.each do |load_path|
1196:       globbed = Dir["#{File.expand_path path, load_path}#{Gem.suffix_pattern}"]
1197: 
1198:       globbed.each do |load_path_file|
1199:         files << load_path_file if File.file?(load_path_file.untaint)
1200:       end
1201:     end
1202: 
1203:     load_plugin_files files
1204:   end

The index to insert activated gem paths into the $LOAD_PATH.

Defaults to the site lib directory unless gem_prelude.rb has loaded paths, then it inserts the activated gem‘s paths before the gem_prelude.rb paths so you can override the gem_prelude.rb default $LOAD_PATH paths.

[Source]

     # File lib/rubygems.rb, line 700
700:   def self.load_path_insert_index
701:     index = $LOAD_PATH.index ConfigMap[:sitelibdir]
702: 
703:     if QUICKLOADER_SUCKAGE then
704:       $LOAD_PATH.each_with_index do |path, i|
705:         if path.instance_variables.include?(:@gem_prelude_index) or
706:             path.instance_variables.include?('@gem_prelude_index') then
707:           index = i
708:           break
709:         end
710:       end
711:     end
712: 
713:     index
714:   end

Load plugins as ruby files

[Source]

      # File lib/rubygems.rb, line 1164
1164:   def self.load_plugin_files(plugins)
1165:     plugins.each do |plugin|
1166: 
1167:       # Skip older versions of the GemCutter plugin: Its commands are in
1168:       # RubyGems proper now.
1169: 
1170:       next if plugin =~ /gemcutter-0\.[0-3]/
1171: 
1172:       begin
1173:         load plugin
1174:       rescue ::Exception => e
1175:         details = "#{plugin.inspect}: #{e.message} (#{e.class})"
1176:         warn "Error loading RubyGems plugin #{details}"
1177:       end
1178:     end
1179:   end

Find all ‘rubygems_plugin’ files in installed gems and load them

[Source]

      # File lib/rubygems.rb, line 1184
1184:   def self.load_plugins
1185:     load_plugin_files find_files('rubygems_plugin', false)
1186:   end

Loads YAML, preferring Psych

[Source]

     # File lib/rubygems.rb, line 719
719:   def self.load_yaml
720:     require 'psych'
721:   rescue ::LoadError
722:   ensure
723:     require 'yaml'
724:   end

[Source]

      # File lib/rubygems.rb, line 1087
1087:   def self.loaded_path? path
1088:     # TODO: ruby needs a feature to let us query what's loaded in 1.8 and 1.9
1089:     $LOADED_FEATURES.find { |s|
1090:       s =~ /(^|\/)#{Regexp.escape path}#{Regexp.union(*Gem.suffixes)}$/
1091:     }
1092:   end

The file name and line number of the caller of the caller of this method.

[Source]

     # File lib/rubygems.rb, line 729
729:   def self.location_of_caller
730:     caller[1] =~ /(.*?):(\d+).*?$/i
731:     file = $1
732:     lineno = $2.to_i
733: 
734:     # TODO: it is ALWAYS joined! STUPID!
735:     [file, lineno]
736:   end

The version of the Marshal format for your Ruby.

[Source]

     # File lib/rubygems.rb, line 741
741:   def self.marshal_version
742:     "#{Marshal::MAJOR_VERSION}.#{Marshal::MINOR_VERSION}"
743:   end

Array of paths to search for Gems.

[Source]

     # File lib/rubygems.rb, line 748
748:   def self.path
749:     @gem_path ||= nil
750: 
751:     unless @gem_path then
752:       paths = [ENV['GEM_PATH'] || default_path]
753: 
754:       if defined?(APPLE_GEM_HOME) and not ENV['GEM_PATH'] then
755:         paths << APPLE_GEM_HOME
756:       end
757: 
758:       set_paths paths.compact.join(File::PATH_SEPARATOR)
759:     end
760: 
761:     @gem_path
762:   end

Array of platforms this RubyGems supports.

[Source]

     # File lib/rubygems.rb, line 795
795:   def self.platforms
796:     @platforms ||= []
797:     if @platforms.empty?
798:       @platforms = [Gem::Platform::RUBY, Gem::Platform.local]
799:     end
800:     @platforms
801:   end

Set array of platforms this RubyGems supports (primarily for testing).

[Source]

     # File lib/rubygems.rb, line 788
788:   def self.platforms=(platforms)
789:     @platforms = platforms
790:   end

Adds a post-build hook that will be passed an Gem::Installer instance when Gem::Installer#install is called. The hook is called after the gem has been extracted and extensions have been built but before the executables or gemspec has been written. If the hook returns false then the gem‘s files will be removed and the install will be aborted.

[Source]

     # File lib/rubygems.rb, line 810
810:   def self.post_build(&hook)
811:     @post_build_hooks << hook
812:   end

Adds a post-install hook that will be passed an Gem::Installer instance when Gem::Installer#install is called

[Source]

     # File lib/rubygems.rb, line 818
818:   def self.post_install(&hook)
819:     @post_install_hooks << hook
820:   end

Adds a post-uninstall hook that will be passed a Gem::Uninstaller instance and the spec that was uninstalled when Gem::Uninstaller#uninstall is called

[Source]

     # File lib/rubygems.rb, line 827
827:   def self.post_uninstall(&hook)
828:     @post_uninstall_hooks << hook
829:   end

Adds a pre-install hook that will be passed an Gem::Installer instance when Gem::Installer#install is called. If the hook returns false then the install will be aborted.

[Source]

     # File lib/rubygems.rb, line 836
836:   def self.pre_install(&hook)
837:     @pre_install_hooks << hook
838:   end

Adds a pre-uninstall hook that will be passed an Gem::Uninstaller instance and the spec that will be uninstalled when Gem::Uninstaller#uninstall is called

[Source]

     # File lib/rubygems.rb, line 845
845:   def self.pre_uninstall(&hook)
846:     @pre_uninstall_hooks << hook
847:   end

The directory prefix this RubyGems was installed at. If your prefix is in a standard location (ie, rubygems is installed where you‘d expect it to be), then prefix returns nil.

[Source]

     # File lib/rubygems.rb, line 854
854:   def self.prefix
855:     prefix = File.dirname RUBYGEMS_DIR
856: 
857:     if prefix != File.expand_path(ConfigMap[:sitelibdir]) and
858:        prefix != File.expand_path(ConfigMap[:libdir]) and
859:        'lib' == File.basename(RUBYGEMS_DIR) then
860:       prefix
861:     end
862:   end

Promotes the load paths of the gem_name over the load paths of over_name. Useful for allowing one gem to override features in another using find_files.

[Source]

     # File lib/rubygems.rb, line 869
869:   def self.promote_load_path(gem_name, over_name)
870:     gem = Gem.loaded_specs[gem_name]
871:     over = Gem.loaded_specs[over_name]
872: 
873:     raise ArgumentError, "gem #{gem_name} is not activated" if gem.nil?
874:     raise ArgumentError, "gem #{over_name} is not activated" if over.nil?
875: 
876:     last_gem_path = File.join gem.full_gem_path, gem.require_paths.last
877: 
878:     over_paths = over.require_paths.map do |path|
879:       File.join over.full_gem_path, path
880:     end
881: 
882:     over_paths.each do |path|
883:       $LOAD_PATH.delete path
884:     end
885: 
886:     gem = $LOAD_PATH.index(last_gem_path) + 1
887: 
888:     $LOAD_PATH.insert(gem, *over_paths)
889:   end

Safely read a file in binary mode on all platforms.

[Source]

     # File lib/rubygems.rb, line 903
903:   def self.read_binary(path)
904:     File.open path, binary_mode do |f| f.read end
905:   end

Refresh source_index from disk and clear searcher.

[Source]

     # File lib/rubygems.rb, line 894
894:   def self.refresh
895:     source_index.refresh!
896: 
897:     @searcher = nil
898:   end

Full path to libfile in gemname. Searches for the latest gem unless requirements is given.

[Source]

     # File lib/rubygems.rb, line 935
935:   def self.required_location(gemname, libfile, *requirements)
936:     requirements = Gem::Requirement.default if requirements.empty?
937: 
938:     matches = Gem.source_index.find_name gemname, requirements
939: 
940:     return nil if matches.empty?
941: 
942:     spec = matches.last
943:     spec.require_paths.each do |path|
944:       result = File.join spec.full_gem_path, path, libfile
945:       return result if File.exist? result
946:     end
947: 
948:     nil
949:   end

The path to the running Ruby interpreter.

[Source]

     # File lib/rubygems.rb, line 954
954:   def self.ruby
955:     if @ruby.nil? then
956:       @ruby = File.join(ConfigMap[:bindir],
957:                         ConfigMap[:ruby_install_name])
958:       @ruby << ConfigMap[:EXEEXT]
959: 
960:       # escape string in case path to ruby executable contain spaces.
961:       @ruby.sub!(/.*\s.*/m, '"\&"')
962:     end
963: 
964:     @ruby
965:   end

Allows setting path to ruby. This method is available when requiring ‘rubygems/test_case‘

[Source]

    # File lib/rubygems/test_case.rb, line 56
56:   def self.ruby= ruby
57:     @ruby = ruby
58:   end

A wrapper around RUBY_ENGINE const that may not be defined

[Source]

    # File lib/rubygems/defaults.rb, line 92
92:   def self.ruby_engine
93:     if defined? RUBY_ENGINE then
94:       RUBY_ENGINE
95:     else
96:       'ruby'
97:     end
98:   end

A Gem::Version for the currently running ruby.

[Source]

      # File lib/rubygems.rb, line 993
 993:   def self.ruby_version
 994:     return @ruby_version if defined? @ruby_version
 995:     version = RUBY_VERSION.dup
 996: 
 997:     if defined?(RUBY_PATCHLEVEL) && RUBY_PATCHLEVEL != -1 then
 998:       version << ".#{RUBY_PATCHLEVEL}"
 999:     elsif defined?(RUBY_REVISION) then
1000:       version << ".dev.#{RUBY_REVISION}"
1001:     end
1002: 
1003:     @ruby_version = Gem::Version.new version
1004:   end

The GemPathSearcher object used to search for matching installed gems.

[Source]

      # File lib/rubygems.rb, line 1009
1009:   def self.searcher
1010:     @searcher ||= Gem::GemPathSearcher.new
1011:   end

Allows setting the gem path searcher. This method is available when requiring ‘rubygems/test_case‘

[Source]

    # File lib/rubygems/test_case.rb, line 32
32:   def self.searcher=(searcher)
33:     @searcher = searcher
34:   end

Returns the Gem::SourceIndex of specifications that are in the Gem.path

[Source]

      # File lib/rubygems.rb, line 1050
1050:   def self.source_index
1051:     @@source_index ||= SourceIndex.new Gem::SourceIndex.installed_spec_directories
1052:   end

Allows setting the default SourceIndex. This method is available when requiring ‘rubygems/test_case‘

[Source]

    # File lib/rubygems/test_case.rb, line 40
40:   def self.source_index=(si)
41:     @@source_index = si
42:   end

Returns an Array of sources to fetch remote gems from. If the sources list is empty, attempts to load the "sources" gem, then uses default_sources if it is not installed.

[Source]

      # File lib/rubygems.rb, line 1059
1059:   def self.sources
1060:     if @sources.empty? then
1061:       begin
1062:         gem 'sources', '> 0.0.1'
1063:         require 'sources'
1064:       rescue LoadError
1065:         @sources = default_sources
1066:       end
1067:     end
1068: 
1069:     @sources
1070:   end

Need to be able to set the sources without calling Gem.sources.replace since that would cause an infinite loop.

[Source]

      # File lib/rubygems.rb, line 1076
1076:   def self.sources=(new_sources)
1077:     @sources = new_sources
1078:   end

Is SSL (used by the signing commands) available on this platform?

[Source]

    # File lib/rubygems/gem_openssl.rb, line 19
19:     def ssl_available?
20:       @ssl_available
21:     end

Glob pattern for require-able path suffixes.

[Source]

      # File lib/rubygems.rb, line 1083
1083:   def self.suffix_pattern
1084:     @suffix_pattern ||= "{#{suffixes.join(',')}}"
1085:   end

Suffixes for require-able paths.

[Source]

      # File lib/rubygems.rb, line 1097
1097:   def self.suffixes
1098:     @suffixes ||= ['',
1099:                    '.rb',
1100:                    *%w(DLEXT DLEXT2).map { |key|
1101:                      val = RbConfig::CONFIG[key]
1102:                      next unless val and not val.empty?
1103:                      ".#{val}"
1104:                    }
1105:                   ].compact.uniq
1106:   end

Prints the amount of time the supplied block takes to run using the debug UI output.

[Source]

      # File lib/rubygems.rb, line 1112
1112:   def self.time(msg, width = 0, display = Gem.configuration.verbose)
1113:     now = Time.now
1114: 
1115:     value = yield
1116: 
1117:     elapsed = Time.now - now
1118: 
1119:     ui.say "%2$*1$s: %3$3.3fs" % [-width, msg, elapsed] if display
1120: 
1121:     value
1122:   end

Try to activate a gem containing path. Returns true if activation succeeded or wasn‘t needed because it was already activated. Returns false if it can‘t find the path in a gem.

[Source]

     # File lib/rubygems.rb, line 202
202:   def self.try_activate path
203:     # finds the _latest_ version... regardless of loaded specs and their deps
204: 
205:     # TODO: use find_all and bork if ambiguous
206: 
207:     spec = Gem.searcher.find path
208:     return false unless spec
209: 
210:     begin
211:       Gem.activate spec.name, "= #{spec.version}"
212:     rescue Gem::LoadError # this could fail due to gem dep collisions, go lax
213:       Gem.activate spec.name
214:     end
215: 
216:     return true
217:   end

Lazily loads DefaultUserInteraction and returns the default UI.

[Source]

      # File lib/rubygems.rb, line 1127
1127:   def self.ui
1128:     require 'rubygems/user_interaction'
1129: 
1130:     Gem::DefaultUserInteraction.ui
1131:   end

[Source]

     # File lib/rubygems.rb, line 343
343:   def self.unresolved_deps
344:     @unresolved_deps ||= Hash.new { |h, n| h[n] = Gem::Dependency.new n }
345:   end

Use the home and paths values for Gem.dir and Gem.path. Used mainly by the unit tests to provide environment isolation.

[Source]

      # File lib/rubygems.rb, line 1137
1137:   def self.use_paths(home, paths=[])
1138:     clear_paths
1139:     set_home(home) if home
1140:     set_paths(paths.join(File::PATH_SEPARATOR)) if paths
1141:   end

Path for gems in the user‘s home directory

[Source]

    # File lib/rubygems/defaults.rb, line 35
35:   def self.user_dir
36:     File.join Gem.user_home, '.gem', ruby_engine, ConfigMap[:ruby_version]
37:   end

The home directory for the user.

[Source]

      # File lib/rubygems.rb, line 1146
1146:   def self.user_home
1147:     @user_home ||= find_home
1148:   end

Allows toggling Windows behavior. This method is available when requiring ‘rubygems/test_case‘

[Source]

    # File lib/rubygems/test_case.rb, line 48
48:   def self.win_platform=(val)
49:     @@win_platform = val
50:   end

Is this a windows platform?

[Source]

      # File lib/rubygems.rb, line 1153
1153:   def self.win_platform?
1154:     if @@win_platform.nil? then
1155:       @@win_platform = !!WIN_PATTERNS.find { |r| RUBY_PLATFORM =~ r }
1156:     end
1157: 
1158:     @@win_platform
1159:   end

[Validate]