From: Jeremy Bopp Date: 2012-09-04T23:30:38+09:00 Subject: Re: Socket Decorator On 09/04/2012 07:34 AM, Bernhard Brodowsky wrote: > Since the length of the messages I send through the internal sockets are > fixed (because of the kind of transformations I do), I should probably > use an internal buffer and for example return the next byte of that > buffer if getc is called and if the buffer is empty, receive the next > message and put it into the buffer. But what should I use for the > buffer? I could use a string, but I guess +=ing and splitting strings > all the time may not be the most efficient way to do it. > > Does anyone see a good solution to my problem, how I could implement > this in an elegant way with some meta programming trick or so without > having to implement all the gets puts send recv etc myself? Take a look at the io-like gem: https://rubygems.org/gems/io-like It provides a fairly easy way to emulate the IO interface; however, I haven't updated it yet to emulate Ruby 1.9 IO details. Ruby 1.8.7 is the limit for now. -Jeremy