I want to open a file for writing but only if it doesn't already exist. If the file exists I want to raise an exception. Is this the best way to do it?
filename = 'foo'
raise if File.exists? filename
File.open(filename, 'w') do |file|
file.write contents
end
What is the most idiomatic way to do this without the race condition?