Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Pathname#delete
() -> ::Integer
delete
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 2995
def unlink()
Dir.unlink @path
rescue Errno::ENOTDIR
File.unlink @path
end
Alias of #unlink
Removes the entry (hard link) at the path in self; returns 0 if a directory, 1 otherwise:
Example
pn_file = Pathname('/tmp/t.txt') pn_file.write('foo') pn_file.unlink # => 1 pn_dir = Pathname('/tmp/foo') pn_dir.mkdir pn_dir.unlink # => 0
If the removed hard link is the last one associated the inode, also removes the inode; otherwise, not. See Unlinking.
Does not follow symbolic links; if the entry is a symbolic link, removes the entry itself (not the link target).
Example
pn_file = Pathname('/tmp/t.txt') pn_link = Pathname('/tmp/link') pn_file.write('foo') pn_link.make_symlink(pn_file) pn_link.unlink # => 1 pn_file.exist? # => true # Link was not followed. pn_file.unlink # => 1