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#writable?

() -> bool
writable? → true or false

Returns whether the entry at the path in self exists and is writable by the effective owner and group in the current process:

Example
filepath = '/tmp/secret.txt'
File.write(filepath, 'foo')
File.stat(filepath).writable? # => true   # Writable.
File.chmod(0o000, filepath)               # Make non-writable.
File.stat(filepath).writable? # => false  # Not writable.
File.delete(filepath)                     # Clean up.
File.stat('/etc').writable?   # => false  # Directory.

Note that filesystem security features may cause this method to return true even when the file is not writable by the effective owner and group.