Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
File.world_readable?
(::path | ::IO file_name) -> ::Integer?
File.world_readable?(object) → integer or nil
file.c
View on GitHub ↗
static VALUE
rb_file_world_readable_p(VALUE obj, VALUE fname)
{
#ifdef S_IROTH
struct stat st;
if (rb_stat(fname, &st) < 0) return Qnil;
if ((st.st_mode & (S_IROTH)) == S_IROTH) {
return UINT2NUM(st.st_mode & (S_IRUGO|S_IWUGO|S_IXUGO));
}
#endif
return Qnil;
}
If the the given object exists and is readable by others, returns the integer permissions for the entry; otherwise, returns nil:
Example
filepath = '/tmp/t.tmp' File.world_readable?(filepath) # => nil # Non-existent. File.write(filepath, 'foo') # Create file. File.world_readable?(filepath).to_s(8) # => "664" # World-readable. File.chmod(0o000, filepath) # Change to unreadable. File.world_readable?(filepath) # => nil # Not world-readable. File.delete(filepath) # Clean up. File.world_readable?('.').to_s(8) # => "775" # Directory. File.world_readable?($stdin) # => nil # IO object.