Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Pathname#rmtree
() -> self
rmtree(noop: nil, verbose: nil, secure: nil) → self
lib/pathname.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/pathname.rb, line 108
def rmtree(noop: nil, verbose: nil, secure: nil)
# The name "rmtree" is borrowed from File::Path of Perl.
# File::Path provides "mkpath" and "rmtree".
require 'fileutils'
FileUtils.rm_rf(@path, noop: noop, verbose: verbose, secure: secure)
self
end
Deletes the entire filetree at the path in self; returns self:
Example
dir_pn = Pathname('foo/bar/baz') # => #<Pathname:foo/bar/baz> dir_pn.mkpath # Create 'baz' and intermediate directories. file_pn = dir_pn.join('t.tmp') # => #<Pathname:foo/bar/baz/t.tmp> file_pn.write('foo') # Create file at nested directory 'baz'. Pathname('foo').rmtree # Delete the entire tree at directory 'foo'. Pathname('foo').exist? # => false
Use method rmdir to delete a single (empty) directory.
See FileUtils.rm_rf for keyword arguments.