diff options
Diffstat (limited to 'ext/pathname')
-rw-r--r-- | ext/pathname/lib/pathname.rb | 3 | ||||
-rw-r--r-- | ext/pathname/pathname.c | 12 |
2 files changed, 12 insertions, 3 deletions
diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index 44152b9b6c..487402c21b 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -512,9 +512,6 @@ end class Pathname # * File * - # See <tt>File.dirname</tt>. Returns all but the last component of the path. - def dirname() self.class.new(File.dirname(@path)) end - # See <tt>File.extname</tt>. Returns the file's extension. def extname() File.extname(@path) end diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c index 36e5cb378a..e548ac56f5 100644 --- a/ext/pathname/pathname.c +++ b/ext/pathname/pathname.c @@ -439,6 +439,17 @@ path_basename(int argc, VALUE *argv, VALUE self) } /* + * See <tt>File.dirname</tt>. Returns all but the last component of the path. + */ +static VALUE +path_dirname(VALUE self) +{ + VALUE str = get_strpath(self); + str = rb_funcall(rb_cFile, rb_intern("dirname"), 1, str); + return rb_class_new_instance(1, &str, rb_obj_class(self)); +} + +/* * == Pathname * * Pathname represents a pathname which locates a file in a filesystem. @@ -658,4 +669,5 @@ Init_pathname() rb_define_method(rb_cPathname, "truncate", path_truncate, 1); rb_define_method(rb_cPathname, "utime", path_utime, 2); rb_define_method(rb_cPathname, "basename", path_basename, -1); + rb_define_method(rb_cPathname, "dirname", path_dirname, 0); } |