Kernel#load
static VALUE
rb_f_load(int argc, VALUE *argv, VALUE _)
{
VALUE fname, wrap;
rb_scan_args(argc, argv, "11", &fname, &wrap);
return load_entrypoint_internal(fname, wrap);
}
Loads and executes the Ruby program in the file filename.
If the filename is an absolute path (e.g. starts with ‘/’), the file will be loaded directly using the absolute path.
If the filename is an explicit relative path (e.g. starts with ‘./’ or ‘../’), the file will be loaded using the relative path from the current directory.
Otherwise, the file will be searched for in the library directories listed in $LOAD_PATH ($:). If the file is found in a directory, it will attempt to load the file relative to that directory. If the file is not found in any of the directories in $LOAD_PATH, the file will be loaded using the relative path from the current directory.
If the file doesn’t exist when there is an attempt to load it, a LoadError will be raised.
If the optional wrap parameter is true, the loaded script will be executed under an anonymous module. If the optional wrap parameter is a module, the loaded script will be executed under the given module. In no circumstance will any local variables in the loaded file be propagated to the loading environment.
Ruby version changes
-
3.1
-
Kernel#loadnow accepts a module as the second argument, and will load the file using the given module as the top-level module. [Feature #6210]
-