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_writable?

() -> ::Integer?
world_writable? → integer or nil

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