What is stat.ctime in Ruby?
Overview
The stat property returns the status or information about a particular file. The ctime of stat represents the time at which the directory information of a file is changed, but not the file itself.
Syntax
File.stat(filename).ctime
stat.ctime syntax in Ruby
Parameters
filename: This is the file for which we want the change time.
Return value
This method returns the change time for the file as a Time object.
Code example
Let's look at the code below:
# get file and print its change timeputs "The change time of this file is:"puts File.stat("main.rb").ctime
Code explanation
- Lines 2 and 3: We use
ctimeto get the change time of themain.rbfile, and we print it to the console.