mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
66c25e4ca1
commit
16cd13c051
4 changed files with 23 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Mon Aug 16 21:39:33 2010 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* ext/pathname/pathname.c (path_basename): Pathname#basename translated
|
||||||
|
from pathname.rb.
|
||||||
|
|
||||||
Mon Aug 16 20:26:13 2010 Narihiro Nakamura <narihiro@netlab.jp>
|
Mon Aug 16 20:26:13 2010 Narihiro Nakamura <narihiro@netlab.jp>
|
||||||
|
|
||||||
* gc.c (gc_profile_result): Index begins with 1.
|
* gc.c (gc_profile_result): Index begins with 1.
|
||||||
|
|
|
@ -512,9 +512,6 @@ end
|
||||||
|
|
||||||
class Pathname # * File *
|
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.
|
# See <tt>File.dirname</tt>. Returns all but the last component of the path.
|
||||||
def dirname() self.class.new(File.dirname(@path)) end
|
def dirname() self.class.new(File.dirname(@path)) end
|
||||||
|
|
||||||
|
|
|
@ -423,6 +423,22 @@ path_utime(VALUE self, VALUE atime, VALUE mtime)
|
||||||
return rb_funcall(rb_cFile, rb_intern("utime"), 3, atime, mtime, get_strpath(self));
|
return rb_funcall(rb_cFile, rb_intern("utime"), 3, atime, mtime, get_strpath(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
*
|
*
|
||||||
|
@ -642,4 +658,5 @@ Init_pathname()
|
||||||
rb_define_method(rb_cPathname, "make_symlink", path_make_symlink, 1);
|
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, "truncate", path_truncate, 1);
|
||||||
rb_define_method(rb_cPathname, "utime", path_utime, 2);
|
rb_define_method(rb_cPathname, "utime", path_utime, 2);
|
||||||
|
rb_define_method(rb_cPathname, "basename", path_basename, -1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -915,6 +915,7 @@ class TestPathname < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_basename
|
def test_basename
|
||||||
assert_equal(Pathname("basename"), Pathname("dirname/basename").basename)
|
assert_equal(Pathname("basename"), Pathname("dirname/basename").basename)
|
||||||
|
assert_equal(Pathname("bar"), Pathname("foo/bar.x").basename(".x"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dirname
|
def test_dirname
|
||||||
|
|
Loading…
Add table
Reference in a new issue