From: "Florian Aßmann" Date: 2007-08-24T21:53:58+09:00 Subject: Re: How to append some data at the beginning of a file My solution for this question would be monkey patching the File class: require 'tempfile' class File def self.prepend(path, string) Tempfile.open File.basename(path) do |tempfile| # shift string to tempfile tempfile << string File.open(path, 'r+') do |file| # append original data to tempfile tempfile << file.read # reset file positions file.pos = tempfile.pos = 0 # copy tempfile back to original file file << tempfile.read end end end end Regards Florian