[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Combining IOs and Strings?

lewisd

2/16/2005

I've been experimenting with some modifications to WEBrick, and came
across an interesting little problem I'm not sure how to solve.

I've got a method with a signature something like this:

def appendTo( someData, moreData)
end

If both someData and moreData are Strings, then the method is really easy:
return someData + moreData

The problem is when either (or both) someData and moreData are IOs. I don't
want to read all the lines from the IOs, into a string, and append to
that. It's concievable that the data from the IO may be larger than
memory. What I'd like to do is return an IO from the method, that, when
read from, will return the data from someData, and then the data from
moreData.

Basically what I want to do is create a subclass of IO, maybe called
ArrayIO, that maintains an array of Strings and IO objects, and
progresses through them as it is read from.

Is there a particular subset of the methods in IO that I can override in
an IO subclass, and be confident that my subclass will work?

--
Derek Lewis

===================================================================
Java Web-Application Developer

Email : email@lewisd.com
Cellular : 778.898.5825
Website : http://www....

"If you've got a 5000-line JSP page that has "all in one" support
for three input forms and four follow-up screens, all controlled
by "if" statements in scriptlets, well ... please don't show it
to me :-). Its almost dinner time, and I don't want to lose my
appetite :-)."
- Craig R. McClanahan


1 Answer

Eric Hodel

2/16/2005 5:59:00 AM

0

On 15 Feb 2005, at 16:00, Derek Lewis wrote:

> Is there a particular subset of the methods in IO that I can override
> in
> an IO subclass, and be confident that my subclass will work?

Take a look at StringIO. Generally, just #read, but maybe also #eof?
and a few others.

> --
> Derek Lewis
[strip 15 lines of sig]

Please make your signature fit in about four lines (not including '--
').

--
Eric Hodel - drbrain@segment7.net - http://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04