Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
File::Stat#world_readable?
() -> ::Integer?
world_readable? → integer or nil
file.c
View on GitHub ↗
static VALUE
rb_stat_wr(VALUE obj)
{
#ifdef S_IROTH
rb_io_stat_data *st = get_stat(obj);
if ((st->ST_(mode) & (S_IROTH)) == S_IROTH) {
return UINT2NUM(st->ST_(mode) & (S_IRUGO|S_IWUGO|S_IXUGO));
}
#endif
return Qnil;
}
If the entry in self exists and is readable 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_readable?.to_s(8) # => "664" # World-readable. File.chmod(0o000, filepath) # Make unreadable. File.stat(filepath).world_readable? # => nil # Not world-readable. File.delete(filepath) # Clean up. File.stat('.').world_readable?.to_s(8) # => "775" # Directory.