Created
April 12, 2016 19:33
-
-
Save janfri/1b0425e6c20c433c5beb6c897d1c6f46 to your computer and use it in GitHub Desktop.
This file contains 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' | |
def File.changelines filename, &blk | |
temp = Tempfile.new('changelines') | |
File.foreach(filename) do |line| | |
line = blk.call(line) | |
temp.write(line) | |
end | |
temp.close | |
FileUtils.mv temp.path, filename | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment