Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Find#prune

() -> void
Find.prune

This method is meaningful only within a block given with Find.find.

Inside such a block, “prunes” the traversed file tree by not descending into the current directory:

Example
files = []
Find.find('.') do |path|
  Find.prune if File.basename(path) == 'test'
  next unless File.file?(path) && File.extname(path) == '.rb'
  files << path
end
files.size    # => 6690
files.take(3) # => ["./KNOWNBUGS.rb", "./array.rb", "./ast.rb"]
See also .prune #find also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0