From: Stephen Waits Date: 2006-03-27T06:20:35+09:00 Subject: Re: Ruby-esque approaches to adding a line at the beginning of a file. On Mar 26, 2006, at 12:55 PM, Randy Kramer wrote: > t = "New first line of file.\n" > t = t + open("sample_file") { |f| f.read } > open("sample_file", "w") { |f| f.write(t)} > > However, it doesn't appear (to me) to be very Ruby-esque--I'm > wondering how > others on this list might approach such a task. I think it's as good as anything. You could scrunch it up a bit like this: t = "New First Line\n" + File.read("sample_file") ... --Steve