Class: File
- Inherits:
-
Object
- Object
- File
- Defined in:
- lib/inline.rb
Class Method Summary collapse
-
.write_with_backup(path) ⇒ Object
Equivalent to
File::open
with an associated block, but moves any existing file with the same name to the side first.
Class Method Details
.write_with_backup(path) ⇒ Object
Equivalent to File::open
with an associated block, but moves any existing file with the same name to the side first.
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 |
# File 'lib/inline.rb', line 861 def self.write_with_backup(path) # returns true if file already existed # move previous version to the side if it exists renamed = false if test ?f, path then renamed = true File.rename path, path + ".old" end File.open(path, "w") do |io| yield(io) end return renamed end |