# A `File` is an abstraction of any file object accessible by the program # and is closely associated with class `IO` . `File` includes the methods # of module `FileTest` as class methods, allowing you to write (for # example) `File.exist?("foo")` . # # In the description of [File](File) methods, # *permission bits* are a platform-specific set of bits that indicate # permissions of a file. On Unix-based systems, permissions are viewed as # a set of three octets, for the owner, the group, and the rest of the # world. For each of these entities, permissions may be set to read, # write, or execute the file: # # The permission bits `0644` (in octal) would thus be interpreted as # read/write for owner, and read-only for group and other. Higher-order # bits may also be used to indicate the type of file (plain, directory, # pipe, socket, and so on) and various other special features. If the # permissions are for a directory, the meaning of the execute bit changes; # when set the directory can be searched. # # On non-Posix operating systems, there may be only the ability to make a # file read-only or read-write. In this case, the remaining permission # bits will be synthesized to resemble typical values. For instance, on # Windows NT the default permission bits are `0644`, which means # read/write for owner, read-only for all others. The only change that can # be made is to make the file read-only, which is reported as `0444` . # # Various constants for the methods in [File](File) # can be found in # [File::Constants](https://ruby-doc.org/core-2.6.3/File/Constants.html). class File < IO def self.absolute_path: (String file, ?String dir) -> String def self.atime: (untyped file) -> Time def self.basename: (String file, ?String suffix) -> String def self.binread: (String arg0) -> String | (String arg0, ?Integer arg1) -> String | (String arg0, ?Integer arg1, ?Integer arg2) -> String def self.birthtime: (untyped file) -> Time def self.blockdev?: (String | IO file) -> bool def self.chardev?: (String | IO file) -> bool def self.chmod: (Integer mode, *String files) -> Integer def self.chown: (Integer owner, Integer group, *String files) -> Integer def self.ctime: (untyped file) -> Time def self.delete: (*String files) -> Integer def self.directory?: (String | IO file) -> bool def self.dirname: (String file) -> String def self.executable?: (String file) -> bool def self.executable_real?: (String file) -> bool def self.exist?: (untyped file) -> bool def self.expand_path: (untyped file, ?untyped dir) -> String def self.extname: (String path) -> String def self.file?: (String | IO file) -> bool def self.fnmatch: (String pattern, String path, ?Integer flags) -> bool def self.`ftype`: (String file) -> String def self.grpowned?: (String | IO file) -> bool def self.identical?: (String | IO file_1, String | IO file_2) -> bool def self.join: (*untyped arg0) -> String def self.lchmod: (Integer mode, *String files) -> Integer def self.lchown: (Integer owner, Integer group, *String files) -> Integer def self.link: (String old, String new) -> Integer def self.lstat: (String file) -> File::Stat def self.mtime: (untyped file) -> Time def self.owned?: (String file) -> bool def self.path: (String path) -> String def self.pipe?: (String file) -> bool def self.readable?: (String file) -> bool def self.readable_real?: (String file) -> bool def self.readlink: (String link) -> String def self.realdirpath: (String pathname, ?String dir) -> String def self.realpath: (String pathname, ?String dir) -> String def self.rename: (String old, String new) -> Integer def self.setgid?: (String file) -> bool def self.setuid?: (String file) -> bool def self.size: (String | IO file) -> Integer def self.size?: (String | IO file) -> Integer? def self.socket?: (String | IO file) -> bool def self.split: (String file) -> [ String, String ] def self.stat: (untyped file) -> File::Stat def self.sticky?: (String file) -> bool def self.symlink: (String old, String new) -> Integer def self.symlink?: (String file) -> bool def self.truncate: (String file, Integer arg0) -> Integer def self.umask: (?Integer arg0) -> Integer def self.utime: (Time atime, Time mtime, *String files) -> Integer def self.world_readable?: (String | IO file) -> Integer? def self.world_writable?: (String | IO file) -> Integer? def self.writable?: (String file) -> Integer? def self.writable_real?: (String file) -> Integer? def self.zero?: (String | IO file) -> Integer? # Returns the last access time (a `Time` object) for *file* , or epoch if # *file* has not been accessed. # # ```ruby # File.new("testfile").atime #=> Wed Dec 31 18:00:00 CST 1969 # ``` def atime: () -> Time # Returns the birth time for *file* . # # ```ruby # File.new("testfile").birthtime #=> Wed Apr 09 08:53:14 CDT 2003 # ``` # # If the platform doesn’t have birthtime, raises # [NotImplementedError](https://ruby-doc.org/core-2.6.3/NotImplementedError.html) # . def birthtime: () -> Time def chmod: (Integer mode) -> Integer def chown: (Integer owner, Integer group) -> Integer # Returns the change time for *file* (that is, the time directory # information about the file was changed, not the file itself). # # Note that on Windows (NTFS), returns creation time (birth time). # # ```ruby # File.new("testfile").ctime #=> Wed Apr 09 08:53:14 CDT 2003 # ``` def ctime: () -> Time def flock: (Integer arg0) -> (Integer | TrueClass | FalseClass) def initialize: (String file, ?String mode, ?String perm, ?Integer opt) -> void # Same as `IO#stat`, but does not follow the last symbolic link. Instead, # reports on the link itself. # # ```ruby # File.symlink("testfile", "link2test") #=> 0 # File.stat("testfile").size #=> 66 # f = File.new("link2test") # f.lstat.size #=> 8 # f.stat.size #=> 66 # ``` def lstat: () -> File::Stat # Returns the modification time for *file* . # # ```ruby # File.new("testfile").mtime #=> Wed Apr 09 08:53:14 CDT 2003 # ``` def mtime: () -> Time # Returns the pathname used to create *file* as a string. Does not # normalize the name. # # The pathname may not point to the file corresponding to *file* . For # instance, the pathname becomes void when the file has been moved or # deleted. # # This method raises `IOError` for a *file* created using # `File::Constants::TMPFILE` because they don’t have a pathname. # # ```ruby # File.new("testfile").path #=> "testfile" # File.new("/tmp/../tmp/xxx", "w").path #=> "/tmp/../tmp/xxx" # ``` def path: () -> String # Returns the size of *file* in bytes. # # ```ruby # File.new("testfile").size #=> 66 # ``` def size: () -> Integer def truncate: (Integer arg0) -> Integer def self.fnmatch?: (String pattern, String path, ?Integer flags) -> bool def self.unlink: (*String files) -> Integer # Returns the pathname used to create *file* as a string. Does not # normalize the name. # # The pathname may not point to the file corresponding to *file* . For # instance, the pathname becomes void when the file has been moved or # deleted. # # This method raises `IOError` for a *file* created using # `File::Constants::TMPFILE` because they don’t have a pathname. # # ```ruby # File.new("testfile").path #=> "testfile" # File.new("/tmp/../tmp/xxx", "w").path #=> "/tmp/../tmp/xxx" # ``` def to_path: () -> String end File::ALT_SEPARATOR: NilClass File::APPEND: Integer File::BINARY: Integer File::CREAT: Integer File::DIRECT: Integer File::DSYNC: Integer File::EXCL: Integer File::FNM_CASEFOLD: Integer File::FNM_DOTMATCH: Integer File::FNM_EXTGLOB: Integer File::FNM_NOESCAPE: Integer File::FNM_PATHNAME: Integer File::FNM_SHORTNAME: Integer File::FNM_SYSCASE: Integer File::LOCK_EX: Integer File::LOCK_NB: Integer File::LOCK_SH: Integer File::LOCK_UN: Integer File::NOATIME: Integer File::NOCTTY: Integer File::NOFOLLOW: Integer File::NONBLOCK: Integer File::NULL: String File::PATH_SEPARATOR: String File::RDONLY: Integer File::RDWR: Integer File::RSYNC: Integer File::SEEK_CUR: Integer File::SEEK_DATA: Integer File::SEEK_END: Integer File::SEEK_HOLE: Integer File::SEEK_SET: Integer File::SEPARATOR: String File::SHARE_DELETE: Integer File::SYNC: Integer File::TMPFILE: Integer File::TRUNC: Integer File::WRONLY: Integer module File::Constants end File::Constants::APPEND: Integer File::Constants::BINARY: Integer File::Constants::CREAT: Integer File::Constants::DIRECT: Integer File::Constants::DSYNC: Integer File::Constants::EXCL: Integer File::Constants::FNM_CASEFOLD: Integer File::Constants::FNM_DOTMATCH: Integer File::Constants::FNM_EXTGLOB: Integer File::Constants::FNM_NOESCAPE: Integer File::Constants::FNM_PATHNAME: Integer File::Constants::FNM_SHORTNAME: Integer File::Constants::FNM_SYSCASE: Integer File::Constants::LOCK_EX: Integer File::Constants::LOCK_NB: Integer File::Constants::LOCK_SH: Integer File::Constants::LOCK_UN: Integer File::Constants::NOATIME: Integer File::Constants::NOCTTY: Integer File::Constants::NOFOLLOW: Integer File::Constants::NONBLOCK: Integer File::Constants::NULL: String File::Constants::RDONLY: Integer File::Constants::RDWR: Integer File::Constants::RSYNC: Integer File::Constants::SHARE_DELETE: Integer File::Constants::SYNC: Integer File::Constants::TMPFILE: Integer File::Constants::TRUNC: Integer File::Constants::WRONLY: Integer class File::Stat < Object include Comparable def <=>: (File::Stat other) -> Integer? def atime: () -> Time def birthtime: () -> Time def blksize: () -> Integer? def blockdev?: () -> bool def blocks: () -> Integer? def chardev?: () -> bool def ctime: () -> Time def dev: () -> Integer def dev_major: () -> Integer def dev_minor: () -> Integer def directory?: () -> bool def executable?: () -> bool def executable_real?: () -> bool def file?: () -> bool def `ftype`: () -> String def gid: () -> Integer def grpowned?: () -> bool def initialize: (String file) -> Object def ino: () -> Integer def inspect: () -> String def mode: () -> Integer def mtime: () -> Time def nlink: () -> Integer def owned?: () -> bool def pipe?: () -> bool def rdev: () -> Integer? def rdev_major: () -> Integer def rdev_minor: () -> Integer def read: (?Integer length, ?String outbuf) -> String def readable?: () -> bool def readable_real?: () -> bool def setgid?: () -> bool def setuid?: () -> bool def size: () -> Integer def socket?: () -> bool def sticky?: () -> bool def symlink?: () -> bool def uid: () -> Integer def world_readable?: () -> Integer? def world_writable?: () -> Integer? def writable?: () -> bool def writable_real?: () -> bool def zero?: () -> bool end