Skip to content

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

instance method

File::Stat#symlink?

() -> bool
symlink? → true or false

Returns whether the entry in self (see Snapshot) is a symbolic link:

Example
filepath = '/etc/passwd'
linkpath = '/tmp/foo'
File.symlink(filepath, linkpath)
File.stat(filepath).symlink?  # => false
File.lstat(filepath).symlink? # => false
stat = File.stat(linkpath)    # Snapshot with stat follows link.
stat.symlink?                 # => false
lstat = File.lstat(linkpath)  # Snapshot with lstat does not follow link.
lstat.symlink?                # => true
File.delete(linkpath)         # Clean up.
# Snapshots are unchanged, even when link deleted.
stat.symlink?                 # => false
lstat.symlink?                # => true
See also #sticky? #uid #socket? #world_readable? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0