ruby-changes:17252
From: akr <ko1@a...>
Date: Wed, 15 Sep 2010 07:23:18 +0900 (JST)
Subject: [ruby-changes:17252] Ruby:r29253 (trunk): * ext/pathname/pathname.c (path_entries): Pathname#entries translated
akr 2010-09-15 07:23:09 +0900 (Wed, 15 Sep 2010) New Revision: 29253 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29253 Log: * ext/pathname/pathname.c (path_entries): Pathname#entries translated from pathname.rb. Modified files: trunk/ChangeLog trunk/ext/pathname/lib/pathname.rb trunk/ext/pathname/pathname.c Index: ChangeLog =================================================================== --- ChangeLog (revision 29252) +++ ChangeLog (revision 29253) @@ -1,3 +1,8 @@ +Wed Sep 15 07:22:20 2010 Tanaka Akira <akr@f...> + + * ext/pathname/pathname.c (path_entries): Pathname#entries translated + from pathname.rb. + Wed Sep 15 02:13:44 2010 Aaron Patterson <aaron@t...> * ext/fiddle/closure.c : Don't use FFI closure alloc on OpenBSD. Index: ext/pathname/lib/pathname.rb =================================================================== --- ext/pathname/lib/pathname.rb (revision 29252) +++ ext/pathname/lib/pathname.rb (revision 29253) @@ -486,10 +486,6 @@ class Pathname # * Dir * - # Return the entries (files and subdirectories) in the directory, each as a - # Pathname object. - def entries() Dir.entries(@path).map {|f| self.class.new(f) } end - # Iterates over the entries (files and subdirectories) in the directory. It # yields a Pathname object for each entry. # Index: ext/pathname/pathname.c =================================================================== --- ext/pathname/pathname.c (revision 29252) +++ ext/pathname/pathname.c (revision 29253) @@ -858,6 +858,30 @@ } /* + * Return the entries (files and subdirectories) in the directory, each as a + * Pathname object. + * + * The result may contain the current directory #<Pathname:.> and the parent + * directory #<Pathname:..>. + */ +static VALUE +path_entries(VALUE self) +{ + VALUE klass, str, ary; + long i; + klass = rb_obj_class(self); + str = get_strpath(self); + ary = rb_funcall(rb_cDir, rb_intern("entries"), 1, str); + ary = rb_convert_type(ary, T_ARRAY, "Array", "to_ary"); + for (i = 0; i < RARRAY_LEN(ary); i++) { + VALUE elt = RARRAY_PTR(ary)[i]; + elt = rb_class_new_instance(1, &elt, klass); + rb_ary_store(ary, i, elt); + } + return ary; +} + +/* * == Pathname * * Pathname represents a pathname which locates a file in a filesystem. @@ -1113,4 +1137,5 @@ rb_define_singleton_method(rb_cPathname, "glob", path_s_glob, -1); rb_define_singleton_method(rb_cPathname, "getwd", path_s_getwd, 0); rb_define_singleton_method(rb_cPathname, "pwd", path_s_getwd, 0); + rb_define_method(rb_cPathname, "entries", path_entries, 0); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/