There must be a DRY way to do this without two separate calls to File.open
, and without peeking at what File.open
's default value for permissions
is. Right?
def ensure_file(path, contents, permissions=nil)
if permissions.nil?
File.open(path, 'w') do |f|
f.puts(contents)
end
else
File.open(path, 'w', permissions) do |f|
f.puts(contents)
end
end
end