summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-19 12:52:37 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-19 12:52:37 +0000
commit54f282c2c4102e6b2d3c641054b3c08808788224 (patch)
tree4a2bae73b6c3118135083e95f0cb34d8de507dc0
parent62fed7c91a7a38e0469bbd454d1c4e8c373e91e5 (diff)
* 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--NEWS4
-rw-r--r--ext/pathname/lib/pathname.rb3
-rw-r--r--test/pathname/test_pathname.rb4
4 files changed, 20 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 8204e132e0..b7a74f9040 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -661,6 +661,15 @@ Sat Nov 5 15:45:04 2011 Tanaka Akira <akr@fsij.org>
* 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@callcc.net>
+
+ * 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@fsij.org>
* ext/socket/socket.c (rsock_socketpair0): don't clear
diff --git a/NEWS b/NEWS
index 2b1b7f5e23..58370a6a28 100644
--- a/NEWS
+++ b/NEWS
@@ -46,6 +46,10 @@ with all sufficient information, see the ChangeLog file.
* 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=
diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb
index 90485a2783..4909c2dc23 100644
--- a/ext/pathname/lib/pathname.rb
+++ b/ext/pathname/lib/pathname.rb
@@ -489,6 +489,8 @@ class Pathname # * Find *
# 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 @@ class Pathname # * Find *
# 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\./}, '')) }
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb
index ac9b415022..401bad2d17 100644
--- a/test/pathname/test_pathname.rb
+++ b/test/pathname/test_pathname.rb
@@ -1235,6 +1235,10 @@ class TestPathname < Test::Unit::TestCase
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