From: Jason Voegele Date: 2003-04-09T22:00:49+09:00 Subject: Re: sending a file via http Brian Candler wrote: > irb> a = File.read("/etc/passwd") > NameError: undefined method `read' for File:Class > > Try: > > File.open("album.zip").read Which reminds me again of the handy little utility methods that I've added to class File (see below). 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? matz, your thoughts? class File # Reads the contents of the specified file_name and returns them as # a String. def File.read(file_name) File.open(file_name) { |f| f.read } end # Writes +content+ to the file with the specified +file_name+, # overwriting any existing content of the file. def File.write(file_name, content) File.open(file_name, 'w') { |f| f.write(content) } end # Writes +content+ to the file with the specified +file_name+, # appending to any existing content of the file. def File.append(file_name, content) File.open(file_name, 'a') { |f| f.write(content) } end # Reads the contents of the file with the specified +file_name+ and # passes the contents to the provided block. The contents of the # file are then replaced by whatever is returned from the block. def File.filter(file_name) File.write(file_name, yield(File.read(file_name))) end end -- Jason Voegele "There is an essential core at the center of each man and woman that remains unaltered no matter how life's externals may be transformed or recombined. But it's smaller than we think." -- Gene Wolfe, The Book of the Long Sun