Overview
File class in ruby provides a method that returns true if a given file exists and returns false if a given false doesn’t exist
https://ruby-doc.org/core-3.0.0/File.html#method-c-exist-3F
Here is the signature of this method
exist?(file_name) → true or false
Example
Below is the program for the same.
File.open("temp.txt", "w") do |f|
f.write("Test")
end
puts File.exist?('temp.txt')
Output
true
Note: Check out our system design tutorial series System Design Questions