From 86b26898ebe3bbb53fa76a41fbf12c41a91ce4bd Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 21 Aug 2010 08:37:28 +0000 Subject: [PATCH] * ext/pathname/pathname.c (path_split): Pathname#split translated from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29061 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/pathname/lib/pathname.rb | 8 -------- ext/pathname/pathname.c | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 25bea4852f..84f9093a14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Aug 21 17:36:42 2010 Tanaka Akira + + * ext/pathname/pathname.c (path_split): Pathname#split translated from + pathname.rb. + Fri Aug 20 10:40:04 2010 Tanaka Akira * ext/pathname/pathname.c (path_expand_path): Pathname#expand_path diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index 2056477eef..4d19aa737c 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -510,14 +510,6 @@ class Pathname # * IO * end -class Pathname # * File * - - # See File.split. Returns the #dirname and the #basename in an - # Array. - def split() File.split(@path).map {|f| self.class.new(f) } end -end - - class Pathname # * FileTest * # See FileTest.blockdev?. diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c index 2ebb976de2..1d6b9ac2a3 100644 --- a/ext/pathname/pathname.c +++ b/ext/pathname/pathname.c @@ -474,6 +474,23 @@ path_expand_path(int argc, VALUE *argv, VALUE self) return rb_class_new_instance(1, &str, rb_obj_class(self)); } +/* + * See File.split. Returns the #dirname and the #basename in an Array. + */ +static VALUE +path_split(VALUE self) +{ + VALUE str = get_strpath(self); + VALUE ary, dirname, basename; + ary = rb_funcall(rb_cFile, rb_intern("split"), 1, str); + ary = rb_check_array_type(ary); + dirname = rb_ary_entry(ary, 0); + basename = rb_ary_entry(ary, 1); + dirname = rb_class_new_instance(1, &dirname, rb_obj_class(self)); + basename = rb_class_new_instance(1, &basename, rb_obj_class(self)); + return rb_ary_new3(2, dirname, basename); +} + /* * == Pathname * @@ -697,4 +714,5 @@ Init_pathname() rb_define_method(rb_cPathname, "dirname", path_dirname, 0); rb_define_method(rb_cPathname, "extname", path_extname, 0); rb_define_method(rb_cPathname, "expand_path", path_expand_path, -1); + rb_define_method(rb_cPathname, "split", path_split, 0); }