lib/core/facets/file/rewrite.rb in facets-2.4.4 vs lib/core/facets/file/rewrite.rb in facets-2.4.5

- old
+ new

@@ -36,18 +36,18 @@ mode += "+" if flag & File::Constants::APPEND != 0 else mode.delete!("^b+") end - old_str = File.open(name, "r#{mode}") { |file| file.read } #rescue "" - old_str = str.clone + old_str = open(name, "r#{mode}") { |file| file.read } #rescue "" + old_str = old_str.clone begin new_str = yield(old_str) ensure if old_str != new_str - File.open(name, "w#{mode}") { |file| file.write(new_str) } + open(name, "w#{mode}") { |file| file.write(new_str) } end end end # In place version of #rewrite. This version of method requires that the @@ -70,17 +70,17 @@ mode += "+" if flag & File::Constants::APPEND != 0 else mode.delete!("^b+") end - old_str = File.open(name, "r#{mode}") { |file| file.read } #rescue "" - new_str = str.clone + old_str = open(name, "r#{mode}") { |file| file.read } #rescue "" + new_str = old_str.clone begin yield(new_str) ensure if old_str != new_str - File.open(name, "w#{mode}") { |file| file.write(str) } + open(name, "w#{mode}") { |file| file.write(str) } end end end end