Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
File::Stat#writable_real?
stat.writable_real? → true or false
file.c
View on GitHub ↗
static VALUE
rb_stat_W(VALUE obj)
{
struct stat *st = get_stat(obj);
#ifdef USE_GETEUID
if (getuid() == 0) return Qtrue;
#endif
#ifdef S_IWUSR
if (rb_stat_rowned(obj))
return RBOOL(st->st_mode & S_IWUSR);
#endif
#ifdef S_IWGRP
if (rb_group_member(get_stat(obj)->st_gid))
return RBOOL(st->st_mode & S_IWGRP);
#endif
#ifdef S_IWOTH
if (!(st->st_mode & S_IWOTH)) return Qfalse;
#endif
return Qtrue;
}
Returns true if stat is writable by the real user id of this process.
Example
File.stat("testfile").writable_real? #=> true