Skip to content

Instantly share code, notes, and snippets.

@janfri
Created April 12, 2016 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janfri/1b0425e6c20c433c5beb6c897d1c6f46 to your computer and use it in GitHub Desktop.
Save janfri/1b0425e6c20c433c5beb6c897d1c6f46 to your computer and use it in GitHub Desktop.
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