From: Brian Candler Date: 2003-04-09T22:32:10+09:00 Subject: Re: sending a file via http On Wed, Apr 09, 2003 at 10:00:49PM +0900, Jason Voegele wrote: > Are these methods useful enough that we should consider adding them to > the standard Ruby File class, or should I be content with requiring them > from my 'tools' library? I agree, except it might be an idea to add mode as an optional parameter: def File.read(file_name, mode='r') File.open(file_name, mode) { |f| f.read } end def File.write(file_name, content, mode='w') File.open(file_name, mode) { |f| f.write(content) } end This is for the poor souls in Windows-land who need mode='rb' or whatever to stop their O/S mangling the file. Also eliminates the need for a separate append method. As for this one: def File.filter(file_name, readmode='r', writemode='w') File.write(file_name, yield(File.read(file_name, readmode)), writemode) end If we have this then perhaps there should be a line-by-line filter as well - File.sed ?? But it would have to write a temporary file. Regards, Brian.