Skip to content

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

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.
See also #uid #world_writable? #symlink? #writable? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0