Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Pathname#mtime
() -> ::Time
mtime → time
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 1495
def mtime() File.mtime(@path) end
Returns a Time object containing the time of the most recent modification to the entry represented by self; see File System Timestamps:
Example
# A directory and its Pathname. dir_path = 'doc/foo' dir_pn = Pathname(dir_path) # Create directory; directory mtime established. dir_pn.mkdir dir_pn.mtime # => 2026-06-28 16:38:02.675780521 -0500 # A file therein and its Pathname. file_path = dir_pn.join('t.tmp') file_pn = Pathname(file_path) # Create file; file mtime established; directory mtime updated. file_pn.write('foo') dir_pn.mtime # => 2026-06-28 16:41:23.107750483 -0500 file_pn.mtime # => 2026-06-28 16:41:23.107750483 -0500 # Modify file; file mtime updated; directory mtime unchanged. file_pn.write('bar') dir_pn.mtime # => 2026-06-28 16:41:23.107750483 -0500 file_pn.mtime # => 2026-06-28 16:42:48.869163049 -0500 # Clean up. dir_pn.rmtree