From: Robert Klemme Date: 2004-05-04T20:43:57+09:00 Subject: Re: IO::write "Charles Comstock" schrieb im Newsbeitrag news:c77oll$hog$1@newsreader.wustl.edu... > Yukihiro Matsumoto wrote: > > > Hi, > > > > In message "IO::write" > > on 04/05/04, Charles Comstock writes: > > > > |Why is there only an IO::read, and no equivalent IO::write that takes a > > |filename, a string to write, and an optional offset in the file to start > > |writing at? Or better yet an IO::write(filename[,offset])= string to > > |write to file. I don't know it seems useful to me for quickly writing a > > |response out to a file anyone else? > > > > IO::read is a equivalent of > > > > IO::open(path, "r"){|f| f.read(*args)} > > > > But IO::write that is > > > > IO::open(path, "w"){|f| f.write(*args)} Appending is probably useful, too IO#write ~ IO::open(path, "w"){|f| f.write(*args)} IO#append ~ IO::open(path, "a"){|f| f.write(*args)} > > is, for my eyes, useless for most of the cases. Besides that, I don't > > feel it is intuitive that IO::write to "open, then write once, then > > close". Even if we decide to implement the method, we should prepare > > better name. > > > > matz. > > > > > > The example listed is exactly the use case that I have littered about my > code quite liberally in one of my applications. Often it's not the best > approach to an application but sometimes it's nice to have quick file > records of application state. Did you consider using a logging framework? e.g. log4r http://log4r.sourceforge.net/ > I suggested write because of the > orthagonality between it and read. Perhaps IO::save or IO::serialize. > Save might be interesting as you could alias load to do the same as > read. Would save/load be a more appropriate name? See above. robert