Created
October 26, 2008 18:47
-
-
Save croaky/19928 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'fileutils' | |
| require 'tempfile' | |
| class File | |
| def File.open_safely(path) | |
| result, temp_path = nil, nil | |
| Tempfile.open("#{File.basename($0)}-#{path.hash}") do |file| | |
| result = yield file | |
| temp_path = file.path | |
| end | |
| FileUtils.move temp_path, path | |
| result | |
| end | |
| end | |
| # getting RuntimeError: cannot generate tempfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment