Skip to content

Commit a9ef32e

Browse files
committed
Restore Pathname#realdirpath
1 parent 658648c commit a9ef32e

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

ext/pathname/pathname.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
static VALUE rb_cPathname;
44
static ID id_at_path;
55
static ID id_sub;
6+
static ID id_realdirpath;
67

78
static VALUE
89
get_strpath(VALUE obj)
@@ -83,6 +84,22 @@ path_sub(int argc, VALUE *argv, VALUE self)
8384
return rb_class_new_instance(1, &str, rb_obj_class(self));
8485
}
8586

87+
/*
88+
* Returns the real (absolute) pathname of +self+ in the actual filesystem.
89+
*
90+
* Does not contain symlinks or useless dots, +..+ and +.+.
91+
*
92+
* The last component of the real pathname can be nonexistent.
93+
*/
94+
static VALUE
95+
path_realdirpath(int argc, VALUE *argv, VALUE self)
96+
{
97+
VALUE basedir, str;
98+
rb_scan_args(argc, argv, "01", &basedir);
99+
str = rb_funcall(rb_cFile, id_realdirpath, 2, get_strpath(self), basedir);
100+
return rb_class_new_instance(1, &str, rb_obj_class(self));
101+
}
102+
86103
static void init_ids(void);
87104

88105
void
@@ -102,6 +119,7 @@ InitVM_pathname(void)
102119
rb_cPathname = rb_define_class("Pathname", rb_cObject);
103120
rb_define_method(rb_cPathname, "<=>", path_cmp, 1);
104121
rb_define_method(rb_cPathname, "sub", path_sub, -1);
122+
rb_define_method(rb_cPathname, "realdirpath", path_realdirpath, -1);
105123
}
106124

107125
void
@@ -110,4 +128,5 @@ init_ids(void)
110128
#undef rb_intern
111129
id_at_path = rb_intern("@path");
112130
id_sub = rb_intern("sub");
131+
id_realdirpath = rb_intern("realdirpath");
113132
}

0 commit comments

Comments
 (0)