From: Jim Weirich Date: 2002-02-28T10:17:58+09:00 Subject: Re: RCR 65: IO orthogonalization, improved reusability >>>>> "Sean" == Sean O'Dell writes: Sean> But where I/O is concerned, here's a base implementation Sean> that I use and have found very extensible to all sorts of Sean> streams. Currently, I have stdio, file, sockets (plain and Sean> SSL), string and memory buffers using a system of class Sean> functionally identical to what I describe below: [... Sean's example elided ...] I think I'm looking for smaller, more cohesive abstractions, rather than a single abstraction that handles reading, writing and random seeking. For example, an output stream would respond to puts, putc print, printf, write and flush messages. A simple implementation shell class could be written in implement puts/putc/print/printf in terms of write. I haven't given much thought to an input stream, but certainly it should support read, readline, readlines, readchar, gets, getc, each, each_line, etc, as well as eof/eof?. A similar breakdown could be made for a random stream. Then implementing an output stream could be as simple as implementing write and mixing in OutputShell (or whatever) that implements all the other methods in terms of write. Or writing read and mixing in InputShell to get an input stream. I added an example of this to the http://www.rubygarden.org/ruby?IORCR page on the RubyGarden wiki. -- -- Jim Weirich jweirich@one.net http://w3.one.net/~jweirich --------------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)