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
file.c
View on GitHub ↗
static VALUE
rb_file_readable_p(VALUE obj, VALUE fname)
{
return RBOOL(rb_eaccess(fname, R_OK) >= 0);
}
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