Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

FileTest#world_writable?

(::path | ::io file_name) -> ::Integer?
File.world_writable?(object) → integer or nil

If the given object exists and is writable by others, returns the integer permissions for the entry; otherwise, returns nil:

Example
filepath = '/tmp/t.tmp'
File.world_writable?(filepath)         # => nil    # Non-existent.
File.write(filepath, 'foo')                        # Create file.
File.world_writable?(filepath)         # => nil    # Not world-writable.
File.chmod(0o777, filepath)                        # Make world-writable.
File.world_writable?(filepath).to_s(8) # => "777"  # World-writable.
File.delete(filepath)                              # Clean up.
File.world_writable?('/tmp').to_s(8)   # => "777"  # Directory.
File.world_writable?($stdin)           # => nil    # IO object.