Project

General

Profile

Feature #3608 » lazy_each_child.diff

taw (Tomasz Wegrzanowski), 07/24/2010 10:27 AM

View differences:

ext/pathname/lib/pathname.rb (working copy)
# This method has existed since 1.8.1.
#
def children(with_directory=true)
with_directory = false if @path == '.'
result = []
Dir.foreach(@path) {|e|
next if e == '.' || e == '..'
if with_directory
result << self.class.new(File.join(@path, e))
else
result << self.class.new(e)
end
}
result
each_child(with_directory).to_a
end
# Iterates over the children of the directory
......
# # #<Pathname:src>
# # #<Pathname:man>
#
def each_child(with_directory=true, &b)
children(with_directory).each(&b)
def each_child(with_directory=true)
block_given? or return enum_for(__method__, with_directory)
with_directory = false if @path == '.'
Dir.foreach(@path) {|e|
next if e == '.' || e == '..'
if with_directory
yield self.class.new(File.join(@path, e))
else
yield self.class.new(e)
end
}
end
#
(1-1/2)