diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-08-16 12:40:10 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-08-16 12:40:10 +0000 |
commit | 16cd13c05188bf52c5dfb056f02ebf4574bb1bc3 (patch) | |
tree | f677d7e3a505c3d32a0c0d6283eeaf2edee90ab9 /ext/pathname/pathname.c | |
parent | 66c25e4ca14fda15c4a0d5cd619e573060ebd756 (diff) | |
download | ruby-16cd13c05188bf52c5dfb056f02ebf4574bb1bc3.tar.gz |
* ext/pathname/pathname.c (path_basename): Pathname#basename translated
from pathname.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/pathname/pathname.c')
-rw-r--r-- | ext/pathname/pathname.c | 17 |
1 files changed, 17 insertions, 0 deletions
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); } |