Skip to content

Commit c1be6a3

Browse files
BurdetteLamarpeterzhu2118
authored andcommitted
[DOC] Doc for Pathname#atime
1 parent 0dc4b2e commit c1be6a3

1 file changed

Lines changed: 34 additions & 16 deletions

File tree

pathname_builtin.rb

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,23 +1001,41 @@ def binwrite(...) File.binwrite(@path, ...) end
10011001
# Returns a new Time object containing the time of the most recent
10021002
# access (read or write) to the entry represented by +self+:
10031003
#
1004-
# filepath = 't.tmp'
1005-
# pn = Pathname.new(filepath)
1006-
# File.exist?(filepath) # => false
1007-
# pn.atime # Raises Errno::ENOENT: No such file or directory
1008-
# File.write(filepath, 'foo')
1009-
# pn.atime # => 2026-03-22 13:49:44.5165608 -0500
1010-
# File.read(filepath)
1011-
# pn.atime # => 2026-03-22 13:49:57.5359349 -0500
1012-
# File.delete(filepath)
1004+
# # Work in a temporary directory.
1005+
# require 'tmpdir'
1006+
# Dir.mktmpdir do |tmpdirpath|
1007+
# # A subdirectory therein, and its Pathname.
1008+
# dirpath = File.join(tmpdirpath, 'subdir')
1009+
# Dir.mkdir(dirpath)
1010+
# dir_pn = Pathname(dirpath)
1011+
# puts "Create directory; establishes atime for directory."
1012+
# puts " Directory atime: #{dir_pn.atime}"
1013+
# sleep(1)
1014+
#
1015+
# # A file in the subdirectory, and its Pathname.
1016+
# filepath = File.join(dirpath, 't.txt')
1017+
# puts "Create file; establishes atime for file, updates atime for directory."
1018+
# File.write(filepath, 'foo')
1019+
# file_pn = Pathname(filepath)
1020+
# puts " File atime: #{file_pn.atime}"
1021+
# puts " Directory atime: #{dir_pn.atime}"
1022+
# sleep(1)
1023+
# puts "Write file; updates atimes for file and directory."
1024+
# File.write(filepath, 'bar')
1025+
# puts " File atime: #{file_pn.atime}"
1026+
# puts " Directory atime: #{dir_pn.atime}"
1027+
# end
1028+
#
1029+
# Output:
10131030
#
1014-
# dirpath = 'tmp'
1015-
# Dir.mkdir(dirpath)
1016-
# pn = Pathname.new(dirpath)
1017-
# pn.atime # => 2026-03-31 11:46:35.4813492 -0500
1018-
# Dir.empty?(dirname) # => true
1019-
# pn.atime # => 2026-03-31 11:51:10.1210092 -0500
1020-
# Dir.delete(dirpath)
1031+
# Create directory; establishes atime for directory.
1032+
# Directory atime: 2026-05-14 14:36:43 +0100
1033+
# Create file; establishes atime for file, updates atime for directory.
1034+
# File atime: 2026-05-14 14:36:44 +0100
1035+
# Directory atime: 2026-05-14 14:36:44 +0100
1036+
# Write file; updates atimes for file and directory.
1037+
# File atime: 2026-05-14 14:36:45 +0100
1038+
# Directory atime: 2026-05-14 14:36:45 +0100
10211039
#
10221040
# See {File System Timestamps}[rdoc-ref:file/timestamps.md].
10231041
def atime() File.atime(@path) end

0 commit comments

Comments
 (0)