Class: File::Stat
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
| Instance Chain: 
          self,
          ::Comparable
         | |
| Inherits: | Object | 
| Defined in: | file.c, file.c | 
Overview
Objects of class Stat encapsulate common status information for ::File objects. The information is recorded at the moment the Stat object is created; changes made to the file after that point will not be reflected. Stat objects are returned by IO#stat, stat, #lstat, and lstat. Many of these methods return platform-specific values, and not all values are meaningful on all systems. See also Kernel#test.
Class Method Summary
- 
    
      .new(file_name)  ⇒ Stat 
    
    constructor
    Create a Statobject for the given file name (raising an exception if the file doesn't exist).
Instance Attribute Summary
- 
    
      #blockdev?  ⇒ Boolean 
    
    readonly
    Returns trueif the file is a block device,falseif it isn't or if the operating system doesn't support this feature.
- 
    
      #chardev?  ⇒ Boolean 
    
    readonly
    Returns trueif the file is a character device,falseif it isn't or if the operating system doesn't support this feature.
- 
    
      #directory?  ⇒ Boolean 
    
    readonly
    Returns trueif stat is a directory,falseotherwise.
- 
    
      #executable?  ⇒ Boolean 
    
    readonly
    Returns trueif stat is executable or if the operating system doesn't distinguish executable files from nonexecutable files.
- 
    
      #executable_real?  ⇒ Boolean 
    
    readonly
    Same as #executable?, but tests using the real owner of the process. 
- 
    
      #file?  ⇒ Boolean 
    
    readonly
    Returns trueif stat is a regular file (not a device file, pipe, socket, etc.).
- 
    
      #grpowned?  ⇒ Boolean 
    
    readonly
    Returns true if the effective group id of the process is the same as the group id of stat. 
- 
    
      #owned?  ⇒ Boolean 
    
    readonly
    Returns trueif the effective user id of the process is the same as the owner of stat.
- 
    
      #pipe?  ⇒ Boolean 
    
    readonly
    Returns trueif the operating system supports pipes and stat is a pipe;falseotherwise.
- 
    
      #readable?  ⇒ Boolean 
    
    readonly
    Returns trueif stat is readable by the effective user id of this process.
- 
    
      #readable_real?  ⇒ Boolean 
    
    readonly
    Returns trueif stat is readable by the real user id of this process.
- 
    
      #setgid?  ⇒ Boolean 
    
    readonly
    Returns trueif stat has the set-group-id permission bit set,falseif it doesn't or if the operating system doesn't support this feature.
- 
    
      #setuid?  ⇒ Boolean 
    
    readonly
    Returns trueif stat has the set-user-id permission bit set,falseif it doesn't or if the operating system doesn't support this feature.
- 
    
      #size  ⇒ Integer 
    
    readonly
    Returns the size of stat in bytes. 
- 
    
      #size  ⇒ Integer 
    
    readonly
    Returns the size of stat in bytes. 
- 
    
      #socket?  ⇒ Boolean 
    
    readonly
    Returns trueif stat is a socket,falseif it isn't or if the operating system doesn't support this feature.
- 
    
      #sticky?  ⇒ Boolean 
    
    readonly
    Returns trueif stat has its sticky bit set,falseif it doesn't or if the operating system doesn't support this feature.
- 
    
      #symlink?  ⇒ Boolean 
    
    readonly
    Returns trueif stat is a symbolic link,falseif it isn't or if the operating system doesn't support this feature.
- 
    
      #world_readable?  ⇒ Boolean 
    
    readonly
    If stat is readable by others, returns an integer representing the file permission bits of stat. 
- 
    
      #world_writable?  ⇒ Boolean 
    
    readonly
    If stat is writable by others, returns an integer representing the file permission bits of stat. 
- 
    
      #writable?  ⇒ Boolean 
    
    readonly
    Returns trueif stat is writable by the effective user id of this process.
- 
    
      #writable_real?  ⇒ Boolean 
    
    readonly
    Returns trueif stat is writable by the real user id of this process.
- 
    
      #zero?  ⇒ Boolean 
    
    readonly
    Returns trueif stat is a zero-length file;falseotherwise.
Instance Method Summary
- 
    
      #<=>(other_stat)  ⇒ 1, ... 
    
    Compares Statobjects by comparing their respective modification times.
- 
    
      #atime  ⇒ Time 
    
    Returns the last access time for this file as an object of class ::Time. 
- 
    
      #birthtime  ⇒ Time 
    
    Returns the birth time for stat. 
- 
    
      #blksize  ⇒ Integer? 
    
    Returns the native file system's block size. 
- 
    
      #blocks  ⇒ Integer? 
    
    Returns the number of native file system blocks allocated for this file, or nilif the operating system doesn't support this feature.
- 
    
      #ctime  ⇒ Time 
    
    Returns the change time for stat (that is, the time directory information about the file was changed, not the file itself). 
- 
    
      #dev  ⇒ Integer 
    
    Returns an integer representing the device on which stat resides. 
- 
    
      #dev_major  ⇒ Integer 
    
    Returns the major part of File_Stat#devornil.
- 
    
      #dev_minor  ⇒ Integer 
    
    Returns the minor part of File_Stat#devornil.
- 
    
      #ftype  ⇒ String 
    
    Identifies the type of stat. 
- 
    
      #gid  ⇒ Integer 
    
    Returns the numeric group id of the owner of stat. 
- 
    
      #ino  ⇒ Integer 
    
    Returns the inode number for stat. 
- 
    
      #inspect  ⇒ String 
    
    Produce a nicely formatted description of stat. 
- 
    
      #mode  ⇒ Integer 
    
    Returns an integer representing the permission bits of stat. 
- 
    
      #mtime  ⇒ Time 
    
    Returns the modification time of stat. 
- 
    
      #nlink  ⇒ Integer 
    
    Returns the number of hard links to stat. 
- 
    
      #rdev  ⇒ Integer? 
    
    Returns an integer representing the device type on which stat resides. 
- 
    
      #rdev_major  ⇒ Integer 
    
    Returns the major part of File_Stat#rdevornil.
- 
    
      #rdev_minor  ⇒ Integer 
    
    Returns the minor part of File_Stat#rdevornil.
- 
    
      #uid  ⇒ Integer 
    
    Returns the numeric user id of the owner of stat. 
::Comparable - Included
| #< | Compares two objects based on the receiver's #<=> method, returning true if it returns -1. | 
| #<= | Compares two objects based on the receiver's #<=> method, returning true if it returns -1 or 0. | 
| #== | Compares two objects based on the receiver's #<=> method, returning true if it returns 0. | 
| #> | Compares two objects based on the receiver's #<=> method, returning true if it returns 1. | 
| #>= | Compares two objects based on the receiver's #<=> method, returning true if it returns 0 or 1. | 
| #between? | |
| #clamp | 
Constructor Details
    .new(file_name)  ⇒ Stat   
Create a Stat object for the given file name (raising an exception if the file doesn't exist).
Instance Attribute Details
    #blockdev?  ⇒ Boolean  (readonly)  
    #chardev?  ⇒ Boolean  (readonly)  
    #directory?  ⇒ Boolean  (readonly)  
Returns true if stat is a directory, false otherwise.
File.stat("testfile").directory?   #=> false
File.stat(".").directory?          #=> true
    #executable?  ⇒ Boolean  (readonly)  
Returns true if stat is executable or if the operating system doesn't distinguish executable files from nonexecutable files. The tests are made using the effective owner of the process.
File.stat("testfile").executable?   #=> false
    #executable_real?  ⇒ Boolean  (readonly)  
Same as #executable?, but tests using the real owner of the process.
    #file?  ⇒ Boolean  (readonly)  
    #grpowned?  ⇒ Boolean  (readonly)  
    #owned?  ⇒ Boolean  (readonly)  
    #pipe?  ⇒ Boolean  (readonly)  
Returns true if the operating system supports pipes and stat is a pipe; false otherwise.
    #readable?  ⇒ Boolean  (readonly)  
    #readable_real?  ⇒ Boolean  (readonly)  
Returns true if stat is readable by the real user id of this process.
File.stat("testfile").readable_real?   #=> true
    #setgid?  ⇒ Boolean  (readonly)  
    #setuid?  ⇒ Boolean  (readonly)  
#size ⇒ Integer (readonly)
#size ⇒ Integer (readonly)
    #socket?  ⇒ Boolean  (readonly)  
    #sticky?  ⇒ Boolean  (readonly)  
    #symlink?  ⇒ Boolean  (readonly)  
Returns true if stat is a symbolic link, false if it isn't or if the operating system doesn't support this feature. As File.stat automatically follows symbolic links, symlink? will always be false for an object returned by File.stat.
File.symlink("testfile", "alink")   #=> 0
File.stat("alink").symlink?         #=> false
File.lstat("alink").symlink?        #=> true
    #world_readable?  ⇒ Boolean  (readonly)  
If stat is readable by others, returns an integer representing the file permission bits of stat. Returns nil otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2).
m = File.stat("/etc/passwd").world_readable?  #=> 420
sprintf("%o", m)                              #=> "644"
    #world_writable?  ⇒ Boolean  (readonly)  
If stat is writable by others, returns an integer representing the file permission bits of stat. Returns nil otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2).
m = File.stat("/tmp").world_writable?         #=> 511
sprintf("%o", m)                              #=> "777"
    #writable?  ⇒ Boolean  (readonly)  
    #writable_real?  ⇒ Boolean  (readonly)  
Returns true if stat is writable by the real user id of this process.
File.stat("testfile").writable_real?   #=> true
    #zero?  ⇒ Boolean  (readonly)  
Instance Method Details
    #<=>(other_stat)  ⇒ 1, ...   
#atime ⇒ Time
#birthtime ⇒ Time
Returns the birth time for stat.
If the platform doesn't have birthtime, raises ::NotImplementedError.
File.write("testfile", "foo")
sleep 10
File.write("testfile", "bar")
sleep 10
File.chmod(0644, "testfile")
sleep 10
File.read("testfile")
File.stat("testfile").birthtime   #=> 2014-02-24 11:19:17 +0900
File.stat("testfile").mtime       #=> 2014-02-24 11:19:27 +0900
File.stat("testfile").ctime       #=> 2014-02-24 11:19:37 +0900
File.stat("testfile").atime       #=> 2014-02-24 11:19:47 +0900#blksize ⇒ Integer?
#blocks ⇒ Integer?
#ctime ⇒ Time
#dev ⇒ Integer
#dev_major ⇒ Integer
#dev_minor ⇒ Integer
#ftype ⇒ String
#gid ⇒ Integer
#ino ⇒ Integer
#inspect ⇒ String
Produce a nicely formatted description of stat.
File.stat("/etc/passwd").inspect
   #=> "#<File::Stat dev=0xe000005, ino=1078078, mode=0100644,
   #    nlink=1, uid=0, gid=0, rdev=0x0, size=1374, blksize=4096,
   #    blocks=8, atime=Wed Dec 10 10:16:12 CST 2003,
   #    mtime=Fri Sep 12 15:41:41 CDT 2003,
   #    ctime=Mon Oct 27 11:20:27 CST 2003,
   #    birthtime=Mon Aug 04 08:13:49 CDT 2003>"