Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
File::Stat#inspect
() -> ::String
inspect → string
file.c
View on GitHub ↗
static VALUE
rb_stat_inspect(VALUE self)
{
VALUE str;
size_t i;
static const struct {
const char *name;
VALUE (*func)(VALUE);
} member[] = {
{"dev", rb_stat_dev},
{"ino", rb_stat_ino},
{"mode", rb_stat_mode},
{"nlink", rb_stat_nlink},
{"uid", rb_stat_uid},
{"gid", rb_stat_gid},
{"rdev", rb_stat_rdev},
{"size", rb_stat_size},
{"blksize", rb_stat_blksize},
{"blocks", rb_stat_blocks},
{"atime", rb_stat_atime},
{"mtime", rb_stat_mtime},
{"ctime", rb_stat_ctime},
#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC)
{"birthtime", rb_stat_birthtime},
#endif
};
struct rb_stat* rb_st;
TypedData_Get_Struct(self, struct rb_stat, &stat_data_type, rb_st);
if (!rb_st->initialized) {
return rb_sprintf("#<%s: uninitialized>", rb_obj_classname(self));
}
str = rb_str_buf_new2("#<");
rb_str_buf_cat2(str, rb_obj_classname(self));
rb_str_buf_cat2(str, " ");
for (i = 0; i < sizeof(member)/sizeof(member[0]); i++) {
VALUE v;
if (i > 0) {
rb_str_buf_cat2(str, ", ");
}
rb_str_buf_cat2(str, member[i].name);
rb_str_buf_cat2(str, "=");
v = (*member[i].func)(self);
if (i == 2) { /* mode */
rb_str_catf(str, "0%lo", (unsigned long)NUM2ULONG(v));
}
else if (i == 0 || i == 6) { /* dev/rdev */
rb_str_catf(str, "0x%"PRI_DEVT_PREFIX"x", NUM2DEVT(v));
}
else {
rb_str_append(str, rb_inspect(v));
}
}
rb_str_buf_cat2(str, ">");
return str;
}
Returns a string representation of the entry in the snapshot in self; here we split the returned strings for readability:
Example
puts File.stat('/etc/passwd').inspect.split(', ')
Output:
#<File::Stat dev=0x10302 ino=11141413 mode=0100644 nlink=1 uid=0 gid=0 rdev=0x0 size=3092 blksize=4096 blocks=8 atime=2026-10-07 11:25:01.307589569 -0500 mtime=2025-06-10 11:10:47.358999941 -0500 ctime=2025-06-10 11:10:47.38899994 -0500>
Example
puts File.stat('/etc').inspect.split(', ')
Output:
#<File::Stat dev=0x10302 ino=11141121 mode=040755 nlink=143 uid=0 gid=0 rdev=0x0 size=12288 blksize=4096 blocks=24 atime=2026-10-04 14:29:46.907775905 -0500 mtime=2026-10-07 06:13:35.116915307 -0500 ctime=2026-10-07 06:13:35.116915307 -0500>