Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
File::Stat#world_writable?
() -> ::Integer?
world_writable? → integer or nil
file.c
View on GitHub ↗
static VALUE
rb_stat_ww(VALUE obj)
{
#ifdef S_IWOTH
rb_io_stat_data *st = get_stat(obj);
if ((st->ST_(mode) & (S_IWOTH)) == S_IWOTH) {
return UINT2NUM(st->ST_(mode) & (S_IRUGO|S_IWUGO|S_IXUGO));
}
#endif
return Qnil;
}
If the entry in self exists and is writable by others, returns the integer permissions for the entry; otherwise, returns nil:
Example
filepath = '/tmp/t.tmp' File.write(filepath, 'foo') File.stat(filepath).world_writable? # => nil # Not world-writable. File.chmod(0o777, filepath) # Make world-writable. File.stat(filepath).world_writable?.to_s(8) # => "777" # World-writable. File.delete(filepath) # Clean up. File.stat('/tmp').world_writable?.to_s(8) # => "777" # Directory.