module Kernel

Public Class Methods

open(name, *rest, &block) click to toggle source

Allows the opening of various resources including URIs.

If the first argument responds to the ‘open’ method, ‘open’ is called on it with the rest of the arguments.

If the first argument is a string that begins with xxx://, it is parsed by URI.parse. If the parsed object responds to the ‘open’ method, ‘open’ is called on it with the rest of the arguments.

Otherwise, the original #open is called.

Since open-uri.rb provides OpenURI::OpenRead#open, URI::HTTPS#open and OpenURI::OpenRead#open, Kernelopen can accept URIs and strings that begin with http://, https:// and ftp://. In these cases, the opened file object is extended by OpenURI::Meta.

# File rake/lib/open-uri.rb, line 27
def open(name, *rest, &block) # :doc:
  if name.respond_to?(:open)
    name.open(*rest, &block)
  elsif name.respond_to?(:to_str) &&
        %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name &&
        (uri = URI.parse(name)).respond_to?(:open)
    uri.open(*rest, &block)
  else
    open_uri_original_open(name, *rest, &block)
  end
end
pp(*objs) click to toggle source

prints arguments in pretty form.

pp returns argument(s).

# File rake/lib/pp.rb, line 58
def pp(*objs) # :doc:
  objs.each {|obj|
    PP.pp(obj)
  }
  objs.size <= 1 ? objs.first : objs
end

Public Instance Methods

pretty_inspect() click to toggle source

returns a pretty printed object as a string.

# File rake/lib/pp.rb, line 50
def pretty_inspect
  PP.pp(self, '')
end

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.

Example:

GEM_SKIP=libA:libB ruby -I../libA -I../libB ./mycode.rb
# File rake/lib/rubygems.rb, line 1227
def gem(gem_name, *requirements) # :doc:
  skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
  raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name
  spec = Gem::Dependency.new(gem_name, *requirements).to_spec
  spec.activate if spec
end
open(name, *rest, &block) click to toggle source

Allows the opening of various resources including URIs.

If the first argument responds to the ‘open’ method, ‘open’ is called on it with the rest of the arguments.

If the first argument is a string that begins with xxx://, it is parsed by URI.parse. If the parsed object responds to the ‘open’ method, ‘open’ is called on it with the rest of the arguments.

Otherwise, the original #open is called.

Since open-uri.rb provides OpenURI::OpenRead#open, URI::HTTPS#open and OpenURI::OpenRead#open, Kernelopen can accept URIs and strings that begin with http://, https:// and ftp://. In these cases, the opened file object is extended by OpenURI::Meta.

# File rake/lib/open-uri.rb, line 27
def open(name, *rest, &block) # :doc:
  if name.respond_to?(:open)
    name.open(*rest, &block)
  elsif name.respond_to?(:to_str) &&
        %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name &&
        (uri = URI.parse(name)).respond_to?(:open)
    uri.open(*rest, &block)
  else
    open_uri_original_open(name, *rest, &block)
  end
end
pp(*objs) click to toggle source

prints arguments in pretty form.

pp returns argument(s).

# File rake/lib/pp.rb, line 58
def pp(*objs) # :doc:
  objs.each {|obj|
    PP.pp(obj)
  }
  objs.size <= 1 ? objs.first : objs
end
scanf(format, &b) click to toggle source

Scans STDIN for data matching format. See IO#scanf for details.

See Scanf for details on creating a format string.

You will need to require ‘scanf’ to use #scanf.

# File rake/lib/scanf.rb, line 768
def scanf(format, &b) #:doc:
  STDIN.scanf(format ,&b)
end