module FileTest
FileTest implements file test operations similar to those used in File::Stat. It exists as a standalone module, and its methods are also insinuated into the File class. (Note that this is not done by inclusion: the interpreter cheats).
Public Class Methods
(path | io file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 16
def self?.blockdev?: (path | io file_name) -> bool
Returns true if filepath points to a block device, false otherwise:
File.blockdev?('/dev/sda1') # => true File.blockdev?(File.new('t.tmp')) # => false
(path | io file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 27
def self?.chardev?: (path | io file_name) -> bool
Returns true if filepath points to a character device, false otherwise.
File.chardev?($stdin) # => true File.chardev?('t.txt') # => false
(path | io file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 45
def self?.directory?: (path | io file_name) -> bool
With string object given, returns true if path is a string path leading to a directory, or to a symbolic link to a directory; false otherwise:
File.directory?('.') # => true File.directory?('foo') # => false File.symlink('.', 'dirlink') # => 0 File.directory?('dirlink') # => true File.symlink('t,txt', 'filelink') # => 0 File.directory?('filelink') # => false
Argument path can be an IO object.
(path file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 70
def self?.executable?: (path file_name) -> bool
Returns true if the named file is executable by the effective user and group id of this process. See eaccess(3).
Windows does not support execute permissions separately from read permissions. On Windows, a file is only considered executable if it ends in .bat, .cmd, .com, or .exe.
Note that some OS-level security features may cause this to return true even though the file is not executable by the effective user/group.
(path file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 86
def self?.executable_real?: (path file_name) -> bool
Returns true if the named file is executable by the real user and group id of this process. See access(3).
Windows does not support execute permissions separately from read permissions. On Windows, a file is only considered executable if it ends in .bat, .cmd, .com, or .exe.
Note that some OS-level security features may cause this to return true even though the file is not executable by the real user/group.
(path | io file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 98
def self?.exist?: (path | io file_name) -> bool
Return true if the named file exists.
file_name can be an IO object.
“file exists” means that stat() or fstat() system call is successful.
(path | io file) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 111
def self?.file?: (path | io file) -> bool
Returns true if the named file exists and is a regular file.
file can be an IO object.
If the file argument is a symbolic link, it will resolve the symbolic link and use the file referenced by the link.
(path | io file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 122
def self?.grpowned?: (path | io file_name) -> bool
Returns true if the named file exists and the effective group id of the calling process is the owner of the file. Returns false on Windows.
file_name can be an IO object.
(path | io file_1, path | io file_2) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 142
def self?.identical?: (path | io file_1, path | io file_2) -> bool
Returns true if the named files are identical.
file_1 and file_2 can be an IO object.
open("a", "w") {} p File.identical?("a", "a") #=> true p File.identical?("a", "./a") #=> true File.link("a", "b") p File.identical?("a", "b") #=> true File.symlink("a", "c") p File.identical?("a", "c") #=> true open("d", "w") {} p File.identical?("a", "d") #=> false
(path | io file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 153
def self?.owned?: (path | io file_name) -> bool
Returns true if the named file exists and the effective user id of the calling process is the owner of the file.
file_name can be an IO object.
(path | io file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 165
def self?.pipe?: (path | io file_name) -> bool
Returns true if filepath points to a pipe, false otherwise:
File.mkfifo('tmp/fifo') File.pipe?('tmp/fifo') # => true File.pipe?('t.txt') # => false
(path file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 177
def self?.readable?: (path file_name) -> bool
Returns true if the named file is readable by the effective user and group id of this process. See eaccess(3).
Note that some OS-level security features may cause this to return true even though the file is not readable by the effective user/group.
(path file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 189
def self?.readable_real?: (path file_name) -> bool
Returns true if the named file is readable by the real user and group id of this process. See access(3).
Note that some OS-level security features may cause this to return true even though the file is not readable by the real user/group.
(path | io file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 199
def self?.setgid?: (path | io file_name) -> bool
Returns true if the named file has the setgid bit set.
file_name can be an IO object.
(path | io file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 209
def self?.setuid?: (path | io file_name) -> bool
Returns true if the named file has the setuid bit set.
file_name can be an IO object.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 219
def self?.size: (path | io file_name) -> Integer
Returns the size of file_name.
file_name can be an IO object.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 230
def self?.size?: (path | io file_name) -> Integer?
Returns nil if file_name doesn’t exist or has zero size, the size of the file otherwise.
file_name can be an IO object.
(path | io file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 242
def self?.socket?: (path | io file_name) -> bool
Returns true if filepath points to a socket, false otherwise:
require 'socket' File.socket?(Socket.new(:INET, :STREAM)) # => true File.socket?(File.new('t.txt')) # => false
(path | io file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 252
def self?.sticky?: (path | io file_name) -> bool
Returns true if the named file has the sticky bit set.
file_name can be an IO object.
(path file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 264
def self?.symlink?: (path file_name) -> bool
Returns true if filepath points to a symbolic link, false otherwise:
symlink = File.symlink('t.txt', 'symlink') File.symlink?('symlink') # => true File.symlink?('t.txt') # => false
(path | io file_name) → Integer?
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 280
def self?.world_readable?: (path | io file_name) -> Integer?
If file_name is readable by others, returns an integer representing the file permission bits of file_name. Returns nil otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2).
file_name can be an IO object.
File.world_readable?("/etc/passwd") #=> 420 m = File.world_readable?("/etc/passwd") sprintf("%o", m) #=> "644"
(path | io file_name) → Integer?
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 296
def self?.world_writable?: (path | io file_name) -> Integer?
If file_name is writable by others, returns an integer representing the file permission bits of file_name. Returns nil otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2).
file_name can be an IO object.
File.world_writable?("/tmp") #=> 511 m = File.world_writable?("/tmp") sprintf("%o", m) #=> "777"
(path file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 308
def self?.writable?: (path file_name) -> bool
Returns true if the named file is writable by the effective user and group id of this process. See eaccess(3).
Note that some OS-level security features may cause this to return true even though the file is not writable by the effective user/group.
(path file_name) → bool
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/file_test.rbs, line 320
def self?.writable_real?: (path file_name) -> bool
Returns true if the named file is writable by the real user and group id of this process. See access(3).
Note that some OS-level security features may cause this to return true even though the file is not writable by the real user/group.