[前][次][番号順一覧][スレッド一覧]

ruby-changes:21743

From: akr <ko1@a...>
Date: Sat, 19 Nov 2011 21:52:51 +0900 (JST)
Subject: [ruby-changes:21743] akr:r33792 (trunk): * lib/pathname.rb (Pathname#find): return an enumerator if

akr	2011-11-19 21:52:37 +0900 (Sat, 19 Nov 2011)

  New Revision: 33792

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33792

  Log:
    * lib/pathname.rb (Pathname#find): return an enumerator if
      no block is given.
    
    * test/pathname/test_pathname.rb: add tests for above.
    
    [ruby-dev:44797] [Feature #5572]

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/ext/pathname/lib/pathname.rb
    trunk/test/pathname/test_pathname.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33791)
+++ ChangeLog	(revision 33792)
@@ -661,6 +661,15 @@
 	* ext/socket/init.c (rsock_socket0): extract single socket() call with
 	  CLOEXEC handling from rsock_socket.
 
+Sat Nov  5 13:49:40 2011  Kazuki Tsujimoto  <kazuki@c...>
+
+	* lib/pathname.rb (Pathname#find): return an enumerator if
+	  no block is given.
+
+	* test/pathname/test_pathname.rb: add tests for above.
+
+	[ruby-dev:44797] [Feature #5572]
+
 Sat Nov  5 11:18:12 2011  Tanaka Akira  <akr@f...>
 
 	* ext/socket/socket.c (rsock_socketpair0): don't clear
Index: ext/pathname/lib/pathname.rb
===================================================================
--- ext/pathname/lib/pathname.rb	(revision 33791)
+++ ext/pathname/lib/pathname.rb	(revision 33792)
@@ -489,6 +489,8 @@
   # Pathname#find is an iterator to traverse a directory tree in a depth first
   # manner.  It yields a Pathname for each file under "this" directory.
   #
+  # Returns an enumerator if no block is given.
+  #
   # Since it is implemented by <tt>find.rb</tt>, <tt>Find.prune</tt> can be used
   # to control the traversal.
   #
@@ -496,6 +498,7 @@
   # current directory, not <tt>./</tt>.
   #
   def find # :yield: pathname
+    return to_enum(__method__) unless block_given?
     require 'find'
     if @path == '.'
       Find.find(@path) {|f| yield self.class.new(f.sub(%r{\A\./}, '')) }
Index: NEWS
===================================================================
--- NEWS	(revision 33791)
+++ NEWS	(revision 33792)
@@ -46,6 +46,10 @@
     * Net::IMAP.default_ssl_port
     * Net::IMAP.default_imaps_port
 
+* pathname
+  * extended method:
+    * Pathname#find returns an enumerator if no block is given.
+
 * resolv
   * new methods:
     * Resolv::DNS#timeouts=
Index: test/pathname/test_pathname.rb
===================================================================
--- test/pathname/test_pathname.rb	(revision 33791)
+++ test/pathname/test_pathname.rb	(revision 33792)
@@ -1235,6 +1235,10 @@
       assert_equal([Pathname("."), Pathname("a"), Pathname("b"), Pathname("d"), Pathname("d/x"), Pathname("d/y")], a)
       a = []; Pathname("d").find {|v| a << v }; a.sort!
       assert_equal([Pathname("d"), Pathname("d/x"), Pathname("d/y")], a)
+      a = Pathname(".").find.sort
+      assert_equal([Pathname("."), Pathname("a"), Pathname("b"), Pathname("d"), Pathname("d/x"), Pathname("d/y")], a)
+      a = Pathname("d").find.sort
+      assert_equal([Pathname("d"), Pathname("d/x"), Pathname("d/y")], a)
     }
   end
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]