summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/pathname/lib/pathname.rb3
-rw-r--r--ext/pathname/pathname.c17
2 files changed, 17 insertions, 3 deletions
diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb
index baadec4196..44152b9b6c 100644
--- a/ext/pathname/lib/pathname.rb
+++ b/ext/pathname/lib/pathname.rb
@@ -512,9 +512,6 @@ end
class Pathname # * File *
- # See <tt>File.basename</tt>. Returns the last component of the path.
- def basename(*args) self.class.new(File.basename(@path, *args)) end
-
# See <tt>File.dirname</tt>. Returns all but the last component of the path.
def dirname() self.class.new(File.dirname(@path)) end
diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c
index ca7377c85a..06a904e10e 100644
--- a/ext/pathname/pathname.c
+++ b/ext/pathname/pathname.c
@@ -424,6 +424,22 @@ path_utime(VALUE self, VALUE atime, VALUE mtime)
}
/*
+ * See <tt>File.basename</tt>. Returns the last component of the path.
+ */
+static VALUE
+path_basename(int argc, VALUE *argv, VALUE self)
+{
+ VALUE str = get_strpath(self);
+ VALUE fext;
+ int n;
+ if (rb_scan_args(argc, argv, "01", &fext) == 0)
+ str = rb_funcall(rb_cFile, rb_intern("basename"), 1, str);
+ else
+ str = rb_funcall(rb_cFile, rb_intern("basename"), 2, str, fext);
+ return rb_class_new_instance(1, &str, rb_obj_class(self));
+}
+
+/*
* == Pathname
*
* Pathname represents a pathname which locates a file in a filesystem.
@@ -642,4 +658,5 @@ Init_pathname()
rb_define_method(rb_cPathname, "make_symlink", path_make_symlink, 1);
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);
}