Project

General

Profile

Feature #5572 » 0001-lib-pathname.rb-Pathname-find-return-an-enumerator-i.patch

ktsj (Kazuki Tsujimoto), 11/05/2011 02:01 PM

View differences:

ChangeLog
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.
Sat Nov 5 11:18:12 2011 Tanaka Akira <akr@fsij.org>
* ext/socket/socket.c (rsock_socketpair0): don't clear
NEWS
* 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=
ext/pathname/lib/pathname.rb
# 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.
#
......
# current directory, not <tt>./</tt>.
#
def find(&block) # :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\./}, '')) }
test/pathname/test_pathname.rb
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
    (1-1/1)