Method: Kernel#require_relative

Defined in:
load.c

#require_relative(string) ⇒ Boolean

Ruby tries to load the library named string relative to the directory containing the requiring file. If the file does not exist a LoadError is raised. Returns true if the file was loaded and false if the file was already loaded before.

Returns:

  • (Boolean)
[View source]

1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'load.c', line 1041

VALUE
rb_f_require_relative(VALUE obj, VALUE fname)
{
    VALUE base = rb_current_realfilepath();
    if (NIL_P(base)) {
        rb_loaderror("cannot infer basepath");
    }
    base = rb_file_dirname(base);
    return rb_require_string_internal(rb_file_absolute_path(fname, base), false);
}