Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Pathname#atime
() -> ::Time
atime → time
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 1403
def atime() File.atime(@path) end
Returns a new Time object containing the access time of the entry at the path in self, as reported by the filesystem; see File System Access Time.
For a file, the access time is established when the file is created, and may be updated with the file content is read:
Example
filepath = '/tmp/t.tmp' pn = Pathname(filepath) pn.atime # Raises Errno::ENOENT: No such file or directory. pn.write('foo') # Establishes access time. pn.atime # => 2026-10-04 15:15:10.628255551 -0500 pn.read # Updates access time. pn.atime # => 2026-10-04 15:15:19.770249225 -0500 pn.delete # Clean up.
For a directory, the access time is established when the directory is created, and may be updated when its entries are read:
Example
dirpath = '/tmp/dir' pn = Pathname(dirpath) pn.atime # Raises Errno::ENOENT: No such file or directory. pn.mkdir # Establishes access time. pn.atime # => 2026-10-04 15:19:49.957848452 -0500 pn.entries # Updates access time. pn.atime # => 2026-10-04 15:20:05.677814625 -0500 pn.delete # Clean up.