Skip to content

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

instance method

Pathname#writable?

() -> bool
writable? => true or false

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

Example
pn = Pathname('/tmp/secret.txt')
pn.writable?                # => false  # Non-existent.
pn.write('foo')                         # Create the file.
pn.writable?                # => true   # Writable.
pn.chmod(0o000)                         # Make non-writable.
pn.writable?                # => false  # Not writable.
pn.delete                               # Clean up.
Pathname('/etc/').writable? # => false  # Directory.

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