Class: File
- Inherits:
-
Object
- Object
- File
- Defined in:
- lib/inline.rb
Class Method Summary collapse
-
.write_with_backup(path, content) ⇒ Object
Equivalent to
File::openwith an associated block, but moves any existing file with the same name to the side first.
Class Method Details
.write_with_backup(path, content) ⇒ Object
Equivalent to File::open with an associated block, but moves any existing file with the same name to the side first. Returns renamed path or false if none.
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 |
# File 'lib/inline.rb', line 867 def self.write_with_backup(path, content) renamed = false if File.file? path then renamed = "#{path}.old" begin File.rename path, renamed rescue SystemCallError # in case of race condition # do nothing end end File.write path, content renamed end |