In: |
pathname.rb
|
Parent: | Object |
Pathname#find is a iterator to traverse directory tree in depth first manner. It yields a pathname for each file under the directory which is pointed by self.
Since it is implemented by find.rb, Find.prune can be used to control the traverse.
If self is `.’, yielded pathnames begin with a filename in the current directory, not `./’.
# File pathname.rb, line 477 def find(&block) require 'find' if @path == '.' Find.find(@path) {|f| yield Pathname.new(f.sub(%{\A\./}, '')) } else Find.find(@path) {|f| yield Pathname.new(f) } end end
# File pathname.rb, line 495 def rmtree # The name "rmtree" is borrowed from File::Path of Perl. # File::Path provides "mkpath" and "rmtree". require 'fileutils' FileUtils.rm_r(@path) nil end
# File pathname.rb, line 506 def unlink() if FileTest.directory? @path Dir.unlink @path else File.unlink @path end end
This method is obsoleted at 1.8.1.
# File pathname.rb, line 517 def foreach(*args, &block) # compatibility to 1.8.0. obsoleted. warn "Pathname#foreach is obsoleted. Use each_line or each_entry." if FileTest.directory? @path # For polymorphism between Dir.foreach and IO.foreach, # Pathname#foreach doesn't yield Pathname object. Dir.foreach(@path, *args, &block) else IO.foreach(@path, *args, &block) end end