ruby-changes:17064
From: akr <ko1@a...>
Date: Sat, 21 Aug 2010 17:39:10 +0900 (JST)
Subject: [ruby-changes:17064] Ruby:r29061 (trunk): * ext/pathname/pathname.c (path_split): Pathname#split translated from
akr 2010-08-21 17:37:28 +0900 (Sat, 21 Aug 2010) New Revision: 29061 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29061 Log: * ext/pathname/pathname.c (path_split): Pathname#split translated from pathname.rb. Modified files: trunk/ChangeLog trunk/ext/pathname/lib/pathname.rb trunk/ext/pathname/pathname.c Index: ChangeLog =================================================================== --- ChangeLog (revision 29060) +++ ChangeLog (revision 29061) @@ -1,3 +1,8 @@ +Sat Aug 21 17:36:42 2010 Tanaka Akira <akr@f...> + + * ext/pathname/pathname.c (path_split): Pathname#split translated from + pathname.rb. + Fri Aug 20 10:40:04 2010 Tanaka Akira <akr@f...> * ext/pathname/pathname.c (path_expand_path): Pathname#expand_path Index: ext/pathname/lib/pathname.rb =================================================================== --- ext/pathname/lib/pathname.rb (revision 29060) +++ ext/pathname/lib/pathname.rb (revision 29061) @@ -510,14 +510,6 @@ end -class Pathname # * File * - - # See <tt>File.split</tt>. 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 <tt>FileTest.blockdev?</tt>. Index: ext/pathname/pathname.c =================================================================== --- ext/pathname/pathname.c (revision 29060) +++ ext/pathname/pathname.c (revision 29061) @@ -475,6 +475,23 @@ } /* + * See <tt>File.split</tt>. 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 * * Pathname represents a pathname which locates a file in a filesystem. @@ -697,4 +714,5 @@ 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); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/