ruby-changes:17289
From: akr <ko1@a...>
Date: Sat, 18 Sep 2010 20:19:45 +0900 (JST)
Subject: [ruby-changes:17289] Ruby:r29292 (trunk): * ext/pathname/pathname.c (path_each_entry): Pathname#each_entry
akr 2010-09-18 20:10:36 +0900 (Sat, 18 Sep 2010) New Revision: 29292 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29292 Log: * ext/pathname/pathname.c (path_each_entry): Pathname#each_entry translated from pathname.rb. Modified files: trunk/ChangeLog trunk/ext/pathname/lib/pathname.rb trunk/ext/pathname/pathname.c Index: ChangeLog =================================================================== --- ChangeLog (revision 29291) +++ ChangeLog (revision 29292) @@ -1,3 +1,8 @@ +Sat Sep 18 20:09:51 2010 Tanaka Akira <akr@f...> + + * ext/pathname/pathname.c (path_each_entry): Pathname#each_entry + translated from pathname.rb. + Fri Sep 17 23:44:07 2010 Kouhei Sutou <kou@c...> * lib/rexml/xpath_parser.rb, test/rexml/test_xpath.rb: Index: ext/pathname/lib/pathname.rb =================================================================== --- ext/pathname/lib/pathname.rb (revision 29291) +++ ext/pathname/lib/pathname.rb (revision 29292) @@ -484,19 +484,6 @@ end -class Pathname # * Dir * - - # Iterates over the entries (files and subdirectories) in the directory. It - # yields a Pathname object for each entry. - # - # This method has existed since 1.8.1. - def each_entry(&block) # :yield: pathname - Dir.foreach(@path) {|f| yield self.class.new(f) } - end - -end - - class Pathname # * Find * # # Pathname#find is an iterator to traverse a directory tree in a depth first Index: ext/pathname/pathname.c =================================================================== --- ext/pathname/pathname.c (revision 29291) +++ ext/pathname/pathname.c (revision 29292) @@ -916,7 +916,28 @@ return rb_block_call(rb_cDir, rb_intern("open"), 1, args, 0, 0); } +static VALUE +each_entry_i(VALUE elt, VALUE klass, int argc, VALUE *argv) +{ + return rb_yield(rb_class_new_instance(1, &elt, klass)); +} + /* + * Iterates over the entries (files and subdirectories) in the directory. It + * yields a Pathname object for each entry. + * + * This method has available since 1.8.1. + */ +static VALUE +path_each_entry(VALUE self) +{ + VALUE args[1]; + + args[0] = get_strpath(self); + return rb_block_call(rb_cDir, rb_intern("foreach"), 1, args, each_entry_i, rb_obj_class(self)); +} + +/* * == Pathname * * Pathname represents a pathname which locates a file in a filesystem. @@ -1176,4 +1197,5 @@ rb_define_method(rb_cPathname, "mkdir", path_mkdir, -1); rb_define_method(rb_cPathname, "rmdir", path_rmdir, 0); rb_define_method(rb_cPathname, "opendir", path_opendir, 0); + rb_define_method(rb_cPathname, "each_entry", path_each_entry, 0); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/