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
file.c
View on GitHub ↗
static VALUE
rb_stat_l(VALUE obj)
{
#ifdef S_ISLNK
if (S_ISLNK(get_stat(obj)->ST_(mode))) return Qtrue;
#endif
return Qfalse;
}
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