Project

General

Profile

Actions

Feature #8269

closed

stdlib: Add Find.each_file to accompany Find.find

Added by tommylommykins (Thomas Green) over 11 years ago. Updated over 11 years ago.

Status:
Feedback
Assignee:
-
Target version:
-
[ruby-core:54284]

Description

Often when I use the find module, I am only interested in files.
Since Find.find returns files and directories, I often write code
that looks like this:

Find.find('foo/bar') do |f|
next if File.directory? f

code code code ...
end

To remove the test for directories, a class method, called find.each_file
could be added, which would only yield files.

module Find
def self.each_file(*paths)
block_given? or return enum_for(method, *paths)
self.find(*paths) {|f yield f unless File.directory? f}
end
end


Files

8269_Find_each_file.patch (1.81 KB) 8269_Find_each_file.patch phluid61 (Matthew Kerwin), 04/22/2013 03:06 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0