From: "Erik Bågfors" Date: 2002-03-13T00:02:02+09:00 Subject: Re: write a stream to another On Tue, 2002-03-12 at 15:24, Matt Armstrong wrote: > Thomas S�ndergaard writes: > > >> > I would probably just use: > >> > >> [...] > >> > >> > istream.each { |line| > >> > ostream.write line > >> > } > >> > >> Agreed. Or a bit more efficient: > >> > >> while buf = istream.read(4096) > >> ostream.write(buf) > >> end > > > > You're not thinking declaratively ;-) I want to say what I want it > > to do. Not how to do it. > > > > ostream << istream > > > > seems about right to me. > > Sure, you're talking API and I'm talking implementation. Your IO#<< > could be implemented with the while loop. I just had to try this... class IO alias :origstuff :<< def << (anObject) if anObject.kind_of? IO while buf = anObject.read(4096) self.write(buf) end else origstuff(anObject) end end end f = File.open('/etc/passwd') t = File.open('/tmp/passwd', 'w') t << f t << "test\n" works fine.. /Erik -- Erik B�gfors | erik@bagfors.nu Supporter of free software | GSM +46 733 279 273 fingerprint: 6666 A85B 95D3 D26B 296B 6C60 4F32 2C0B 693D 6E32