End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
File::Stat#writable?
stat.writable? → 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 (geteuid() == 0) return Qtrue;
#endif
#ifdef S_IWUSR
if (rb_stat_owned(obj))
return RBOOL(st->st_mode & S_IWUSR);
#endif
#ifdef S_IWGRP
if (rb_stat_grpowned(obj))
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 effective user id of this process.
Example
File.stat("testfile").writable? #=> true
See also
#world_writable?
#writable_real?
#world_readable?
#zero?
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0