From: "David A. Black" Date: 2007-10-30T21:54:15+09:00 Subject: Re: Is there a better way to do this? (write something to a file Hi -- On Tue, 30 Oct 2007, Chris Richards wrote: > Is there a better way to write text to a file? > > File.open("/file/location/new.txt","w") {|file| file.write "data to > write"} > > It just seems a bit long winded and unmessy Are you sure you mean unmessy? :-) In any case -- I agree, it does have a bit of overhead, and always seems like a lot to write when just writing one thing. It pays for itself when the block contains more logic, of course. You could do: (File.open("file","w") << data).close though that makes the writing seem kind of side-effect-esque. David -- Upcoming training by David A. Black/Ruby Power and Light, LLC: * Advancing With Rails, Edison, NJ, November 6-9 * Advancing With Rails, Berlin, Germany, November 19-22 * Intro to Rails, London, UK, December 3-6 (by Skills Matter) See http://www.rubypal.com for details!