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

(::path file_name) -> bool
File.readable?(path) → true or false

Returns whether the entry at the given path exists and is readable by the owner and group of the current process; see Permissions:

Example
path = '/tmp/secret.txt'
File.write(path, 'foo')
File.readable?(path)     # => true
File.chmod(0o000, path)
File.readable?(path)     # => false
File.delete(path)        # Clean up.
File.readable?('nosuch') # => false
See also #pipe? #readable_real? #owned? #setgid? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0