kernel/common/kernel.rb
##
# Loads the given file as executable code and returns true. If
# the file cannot be found, cannot be compiled or some other
# error occurs, LoadError is raised with an explanation.
#
# Unlike #require, the file extension if any must be present but
# is not restricted to .rb, .rbc or .<platform shared lib ext>.
# Any other extensions (or no extension) are assumed to be plain
# Ruby files. The only exceptions to this rule are:
#
# 1.  if given a .rb or no/any-extensioned file and there is a
#     compiled version of the same file that is not older than
#     the source file (based on File.mtime), the compiled one
#     is loaded directly to avoid the compilation overhead.
# 2.  if a .rb file is given but it does not exist, the system
#     will try to load the corresponding .rbc instead (to allow
#     distributing just .rbc files.)
#
# If the path given starts with ./, ../, ~/ or /, it is treated
# as a "qualified" file and will be loaded directly (after path
# expansion) instead of matching against $LOAD_PATH. The relative
# paths use Dir.pwd.
#
# If the filename is plain (unqualified) then it is sequentially
# prefixed with each path in $LOAD_PATH ($:) to locate the file,
# using the first one that exists. If none of the resulting paths
# exist, LoadError is raised. Unqualified names may contain path
# elements so directories are valid targets and can be used with
# $LOAD_PATH.
#
# A few extra options are supported. If the second parameter is
# true, then the module is wrapped inside an anonymous module for
# loading to avoid polluting the namespace. This is actually a
# shorthand for passing in :wrap => true-ish in the second arg
# which may be an option Hash.
#
# If :recompile in option Hash is true-ish then the file in
# question is recompiled each time. If the source file is not
# present when recompiling is requested, a LoadError is raised.
#
# TODO: Support non-UNIX paths.
#
# TODO: The anonymous module wrapping is not implemented at all.
#
Loads the given file as executable code and returns true. If
the file cannot be found, cannot be compiled or some other
error occurs, LoadError is raised with an explanation.

Unlike #require, the file extension if any must be present but
is not restricted to .rb, .rbc or ..
Any other extensions (or no extension) are assumed to be plain
Ruby files. The only exceptions to this rule are.

1.  if given a .rb or no/any-extensioned file and there is a
compiled version of the same file that is not older than
the source file (based on File.mtime), the compiled one
is loaded directly to avoid the compilation overhead.
2.  if a .rb file is given but it does not exist, the system
will try to load the corresponding .rbc instead (to allow
distributing just .rbc files.)

If the path given starts with ./, ../, ~/ or /, it is treated
as a "qualified" file and will be loaded directly (after path
expansion) instead of matching against $LOAD_PATH. The relative
paths use Dir.pwd.

If the filename is plain (unqualified) then it is sequentially
prefixed with each path in $LOAD_PATH ($:) to locate the file,
using the first one that exists. If none of the resulting paths
exist, LoadError is raised. Unqualified names may contain path
elements so directories are valid targets and can be used with
$LOAD_PATH.

A few extra options are supported. If the second parameter is
true, then the module is wrapped inside an anonymous module for
loading to avoid polluting the namespace. This is actually a
shorthand for passing in :wrap => true-ish in the second arg
which may be an option Hash.

If :recompile in option Hash is true-ish then the file in
question is recompiled each time. If the source file is not
present when recompiling is requested, a LoadError is raised.

Support non-UNIX paths.

The anonymous module wrapping is not implemented at all.
Loads the given file as executable code and returns true . If the file cannot be found cannot be compiled or some other error occurs LoadError is raised with an explanation . Unlike #require the file extension if any must be present but is not restricted to . rb . rbc or .. Any other extensions ( or no extension ) are assumed to be plain Ruby files . The only exceptions to this rule are . 1 . if given a . rb or no / any - extensioned file and there is a compiled version of the same file that is not older than the source file ( based on File . mtime ) the compiled one is loaded directly to avoid the compilation overhead . 2 . if a . rb file is given but it does not exist the system will try to load the corresponding . rbc instead ( to allow distributing just . rbc files . ) If the path given starts with . / .. / ~ / or / it is treated as a " qualified " file and will be loaded directly ( after path expansion ) instead of matching against $LOAD_PATH . The relative paths use Dir . pwd . If the filename is plain ( unqualified ) then it is sequentially prefixed with each path in $LOAD_PATH ( $ : ) to locate the file using the first one that exists . If none of the resulting paths exist LoadError is raised . Unqualified names may contain path elements so directories are valid targets and can be used with $LOAD_PATH . A few extra options are supported . If the second parameter is true then the module is wrapped inside an anonymous module for loading to avoid polluting the namespace . This is actually a shorthand for passing in : wrap = > true - ish in the second arg which may be an option Hash . If : recompile in option Hash is true - ish then the file in question is recompiled each time . If the source file is not present when recompiling is requested a LoadError is raised . Support non - UNIX paths . The anonymous module wrapping is not implemented at all .
def load(path, opts = {:wrap => false, :recompile => false})
    path = StringValue(path)
    path.gsub!(/\.(so|bundle|dll|dylib)$/, "#{Rubinius::LIBSUFFIX}")
    opts = {:wrap => !!opts, :recompile => false} unless Hash === opts
    if path.suffix? '.rbc'
      rb, rbc, ext = nil, path, nil
    elsif path.suffix? '.rb'
      rb, rbc, ext = path, "#{path}c", nil
    elsif path.suffix? "#{Rubinius::LIBSUFFIX}"
      rb, rbc, ext = nil, nil, path
    else
      dir, name = File.split(path)
      rb = path
      ext = nil
      if name[0] == ?.
        rbc = nil
      else
        rbc = "#{dir}/#{name}.compiled.rbc"
      end
    end
    Compiler::Utils.unified_load path, rb, rbc, ext, nil, opts
  end
def load ( path , opts = { :wrap => false , :recompile => false } ) path = StringValue ( path ) path . gsub! ( / \. (so|bundle|dll|dylib)$ / , "#{Rubinius::LIBSUFFIX}" ) opts = { :wrap => ! ! opts , :recompile => false } unless Hash === opts if path . suffix? '.rbc' rb , rbc , ext = nil , path , nil elsif path . suffix? '.rb' rb , rbc , ext = path , "#{path}c" , nil elsif path . suffix? "#{Rubinius::LIBSUFFIX}" rb , rbc , ext = nil , nil , path else dir , name = File . split ( path ) rb = path ext = nil if name [ 0 ] == ?. rbc = nil else rbc = "#{dir}/#{name}.compiled.rbc" end end Compiler :: Utils . unified_load path , rb , rbc , ext , nil , opts end
Loads the given file as executable code and returns true.
Loads the given file as executable code and returns true .
# Remap all library extensions behind the scenes, just like MRI
path
<not_specific>
opts
<not_specific>