Skip to content

Commit 2fda295

Browse files
[DOC] Doc for File::Stat
1 parent fcd2100 commit 2fda295

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

file.c

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5945,13 +5945,48 @@ rb_f_test(int argc, VALUE *argv, VALUE _)
59455945
/*
59465946
* Document-class: File::Stat
59475947
*
5948-
* Objects of class File::Stat encapsulate common status information
5949-
* for File objects. The information is recorded at the moment the
5950-
* File::Stat object is created; changes made to the file after that
5951-
* point will not be reflected. File::Stat objects are returned by
5952-
* IO#stat, File::stat, File#lstat, and File::lstat. Many of these
5953-
* methods return platform-specific values, and not all values are
5954-
* meaningful on all systems. See also Kernel#test.
5948+
* A \File::Stat object contains information about an entry in the file system.
5949+
*
5950+
* Each of these methods returns a new \File::Stat object:
5951+
*
5952+
* - File#lstat.
5953+
* - File::Stat.new.
5954+
* - File::lstat.
5955+
* - File::stat.
5956+
* - IO#stat.
5957+
*
5958+
* === Snapshot
5959+
*
5960+
* A new \File::Stat object takes an immediate "snapshot" of the entry's information;
5961+
* the captured information is never updated,
5962+
* regardless of changes in the actual entry:
5963+
*
5964+
* The entry must exist when File::Stat.new is called:
5965+
*
5966+
* filepath = 't.tmp'
5967+
* File.exist?(filepath) # => false
5968+
* File::Stat.new(filepath) # Raises Errno::ENOENT: No such file or directory.
5969+
* File.write(filepath, 'foo') # Create the file.
5970+
* stat = File::Stat.new(filepath) # Okay.
5971+
*
5972+
* Later changes to the actual entry do not change the \File::Stat object:
5973+
*
5974+
* File.atime(filepath) # => 2026-04-01 11:51:38.0014518 -0500
5975+
* stat.atime # => 2026-04-01 11:51:38.0014518 -0500
5976+
* File.write(filepath, 'bar')
5977+
* File.atime(filepath) # => 2026-04-01 11:58:11.922614 -0500
5978+
* stat.atime # => 2026-04-01 11:51:38.0014518 -0500
5979+
* File.delete(filepath)
5980+
stat.atime # => 2026-04-01 11:51:38.0014518 -0500
5981+
*
5982+
* === OS-Dependencies
5983+
*
5984+
* Methods in a \File::Stat object may return platform-dependents values,
5985+
* and not all values are meaningful on all systems;
5986+
* for example, File::Stat#blocks returns +nil+ on Windows,
5987+
* but returns an integer on Linux.
5988+
*
5989+
* See also Kernel#test.
59555990
*/
59565991

59575992
static VALUE

0 commit comments

Comments
 (0)