Skip to content

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

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
See also #unlink #ctime #descend #cleanpath also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0