summaryrefslogtreecommitdiff
path: root/ext/pathname/pathname.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-17 04:02:32 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-17 04:02:32 +0000
commit05745ccfb367ab670ebbad8c992edf2cf70d8b4b (patch)
tree8efbe141cd852b43f6936d2bb74b5755a319be8a /ext/pathname/pathname.c
parent1572070fa07dfc57cd63d0a2ab14538cf67005eb (diff)
* ext/pathname/pathname.c (path_dirname): Pathname#dirname translated
from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/pathname/pathname.c')
-rw-r--r--ext/pathname/pathname.c12
1 files changed, 12 insertions, 0 deletions
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);
}