Maintenance of Ruby 2.0.0 ended on February 24, 2016. Read more

In Files

  • rubygems/core_ext/kernel_gem.rb
  • rubygems/core_ext/kernel_require.rb

Class/Module Index [+]



Public Instance Methods

gem_original_require(path) click to toggle source

The Kernel#require from before RubyGems was loaded.

Alias for: require

Private Instance Methods

gem(gem_name, *requirements) click to toggle source

Use #gem to activate a specific version of gem_name.

requirements is a list of version requirements that the specified gem must match, most commonly “= example.version.number”. See Gem::Requirement for how to specify a version requirement.

If you will be activating the latest version of a gem, there is no need to call #gem, Kernel#require will do the right thing for you.

#gem returns true if the gem was activated, otherwise false. If the gem could not be found, didn't match the version requirements, or a different version was already activated, an exception will be raised.

#gem should be called before any require statements (otherwise RubyGems may load a conflicting library version).

In older RubyGems versions, the environment variable GEM_SKIP could be used to skip activation of specified gems, for example to test out changes that haven't been installed yet. Now RubyGems defers to -I and the RUBYLIB environment variable to skip activation of a gem.


GEM_SKIP=libA:libB ruby -I../libA -I../libB ./mycode.rb
               # File rubygems/core_ext/kernel_gem.rb, line 32
def gem(gem_name, *requirements) # :doc:
  skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
  raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name

  if gem_name.kind_of? Gem::Dependency
    unless Gem::Deprecate.skip
      warn "#{Gem.location_of_caller.join ':'}:Warning: Kernel.gem no longer "\
        "accepts a Gem::Dependency object, please pass the name "\
        "and requirements directly"

    requirements = gem_name.requirement
    gem_name =

  spec =, *requirements).to_spec
  spec.activate if spec