Index: ext/pathname/lib/pathname.rb =================================================================== --- ext/pathname/lib/pathname.rb (revision 28732) +++ ext/pathname/lib/pathname.rb (working copy) @@ -655,17 +655,7 @@ # 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 @@ -694,8 +684,17 @@ # # # # # # # - 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 #