Here's an example of the data stream approach. require 'roof/datastream' # from Roof on RAA DataStream.open($0, "r+") do |data| while line = data.gets and line != "__END__\n" ## maybe you can do this by seeking to __DATA__.pos, ## but that doesn't seem to work in Ruby 1.6.7 end data.substream do # within this block, data behaves exactly as if everything before # the current pos (which is just after __END__) was deleted. data.print "Here is some data" end end __END__