End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
File::Stat#nlink
stat.nlink → integer
file.c
View on GitHub ↗
static VALUE
rb_stat_nlink(VALUE self)
{
/* struct stat::st_nlink is nlink_t in POSIX. Not the case for Windows. */
const struct stat *ptr = get_stat(self);
if (sizeof(ptr->st_nlink) <= sizeof(int)) {
return UINT2NUM((unsigned)ptr->st_nlink);
}
else if (sizeof(ptr->st_nlink) == sizeof(long)) {
return ULONG2NUM((unsigned long)ptr->st_nlink);
}
else if (sizeof(ptr->st_nlink) == sizeof(LONG_LONG)) {
return ULL2NUM((unsigned LONG_LONG)ptr->st_nlink);
}
else {
rb_bug(":FIXME: don't know what to do");
}
}
Returns the number of hard links to stat.
Example
File.stat("testfile").nlink #=> 1 File.link("testfile", "testfile.bak") #=> 0 File.stat("testfile").nlink #=> 2