示例#1
0
文件: load.c 项目: scorpion007/ruby
/*
 * call-seq:
 *   require_relative(string) -> true or false
 *
 * Ruby tries to load the library named _string_ relative to the requiring
 * file's path.  If the file's path cannot be determined a LoadError is raised.
 * If a file is loaded +true+ is returned and false otherwise.
 */
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_safe(rb_file_absolute_path(fname, base), rb_safe_level());
}
示例#2
0
文件: initrb.c 项目: numinit/initrb
static VALUE initrb_interpreter_begin(VALUE file) {
    /** `file' may be a symlink or a relative path, expand it and dereference all symlinks **/
    VALUE real_name = rb_funcall(rb_cFile, rb_intern("realpath"), 1, file);
    VALUE dir = rb_file_dirname(real_name);

    /** Add the file's directory to the library search path **/
    rb_ary_unshift(rb_gv_get(":"), dir);

    /** Run the interpreter */
    return initrb_interpreter_boot(real_name);
}
示例#3
0
VALUE
rb_dir_s_mkdir_bang( int argc, VALUE *argv)
{
    VALUE path, modes;

    rb_scan_args( argc, argv, "11", &path, &modes);
    if (!rb_file_directory_p( rb_cFile, path)) {
        VALUE parent[2];

        parent[ 0] = rb_file_dirname( path);
        parent[ 1] = modes;
        rb_dir_s_mkdir_bang( 2, parent);
        if (!id_mkdir)
            id_mkdir = rb_intern( "mkdir");
        if (NIL_P(modes))
            rb_funcall( rb_cDir, id_mkdir, 1, path);
        else
            rb_funcall( rb_cDir, id_mkdir, 2, path, modes);
        return path;
    }
    return Qnil;
}