# lets you edit file contents and save to other file # usage: # # edit_file_contents 'file.template', 'file' do |contents| # contents.gsub!(/alpha(.)*/, 'beta') # end # # and the modified contents will be saved in 'dst' file def edit_file_contents src, dst raise "No block given" if ! block_given? contents = "" File.open( src, 'r' ) do |file| contents = file.read end yield contents File.open( dst, 'w' ) do |file| file.write contents end end