From: Massimiliano Mirra Date: 2002-03-16T18:50:16+09:00 Subject: Re: Reading from a string On Sat, Mar 16, 2002 at 05:28:27PM +0900, Thomas Sondergaard wrote: > Have you reimplemented the features like gets, readline, readlines, etc. > from IO or are you using the same implementation? Wouldn't it be nice to > write these features once and for all and make them available to all > (future) stream implementers? > > Would it be possible for you to refactor StringIO, so the implementation > of these convenience methods become available to other "IO" stream > implementers? > > IO RCR: http://www.rubygarden.org/article.php?sid=179 > IO RCR Discussion: http://www.rubygarden.org/ruby?IORCR It's fine for writing (as shown of one of those pages) but I found it troublesome for reading. Basically you'd have to base generic readline, gets and such, on a class-specific implementation of something as small as a getc. Can you see yourself iterating through each byte until you find the pattern? I _think_ it's a bit inefficient compared to (at least non-greedy) regexps. (I'd be happy to be proven wrong, though!) Massimiliano