StringIO#readbytes

Hi,

Is the following patch valuable?
It doesn't work if you require readbytes before stringio!

Regards,

  Michael

--- readbytes.rb.old Fri Jul 9 14:05:58 2004
+++ readbytes.rb Fri Jul 9 14:10:56 2004
@@ -11,7 +11,7 @@
   attr_reader :data
end

-class IO
+module ReadbytesMixin
   def readbytes(n)
     str = read(n)
     if str == nil
@@ -23,6 +23,17 @@
     str
   end
end

···

+
+class IO
+ include ReadbytesMixin
+end
+
+if defined?(StringIO)
+ class StringIO
+ include ReadbytesMixin
+ end
+end
+

if __FILE__ == $0
   begin

Hi,

At Fri, 9 Jul 2004 21:14:38 +0900,
Michael Neumann wrote in [ruby-talk:105707]:

Is the following patch valuable?
It doesn't work if you require readbytes before stringio!

I don't like this, because there are other IO-like classes,
Zlib::GzipReader in bundled library for instance.

Instead, what about separating such class-independent methods
to a couple of modules so those classes can include them?

···

--
Nobu Nakada

Hi,

At Fri, 9 Jul 2004 21:14:38 +0900,
Michael Neumann wrote in [ruby-talk:105707]:
> Is the following patch valuable?
> It doesn't work if you require readbytes before stringio!

I don't like this, because there are other IO-like classes,
Zlib::GzipReader in bundled library for instance.

I agree.

Instead, what about separating such class-independent methods
to a couple of modules so those classes can include them?

Yes, that's a better idea.

Regards,

  Michael

···

On Fri, Jul 09, 2004 at 10:49:45PM +0900, nobu.nokada@softhome.net wrote:

How about putting all methods that depend on read into a module
ReadMixin (another better name for it?). For readbytes.rb this would
look like:

  module ReadMixin
    def readbytes(n)
      ...
    end
  end

  class IO
    include ReadMixin
  end

Maybe IO and all similar classes could by default mix in the ReadMixin
module, so that readbytes.rb would only have to extend the ReadMixin
module for the readbytes method. Of course we'd also need an empty
ReadMixin module in Ruby by default.

Regards,

  Michael

···

On Mon, Jul 12, 2004 at 02:28:38AM +0900, Michael Neumann wrote:

On Fri, Jul 09, 2004 at 10:49:45PM +0900, nobu.nokada@softhome.net wrote:
> Hi,
>
> At Fri, 9 Jul 2004 21:14:38 +0900,
> Michael Neumann wrote in [ruby-talk:105707]:
> > Is the following patch valuable?
> > It doesn't work if you require readbytes before stringio!
>
> I don't like this, because there are other IO-like classes,
> Zlib::GzipReader in bundled library for instance.

I agree.

> Instead, what about separating such class-independent methods
> to a couple of modules so those classes can include them?

Yes, that's a better idea.

Hi,

At Mon, 12 Jul 2004 02:58:34 +0900,
Michael Neumann wrote in [ruby-talk:106007]:

> > > Is the following patch valuable?
> > > It doesn't work if you require readbytes before stringio!
> >
> > I don't like this, because there are other IO-like classes,
> > Zlib::GzipReader in bundled library for instance.
>
> I agree.
>
> > Instead, what about separating such class-independent methods
> > to a couple of modules so those classes can include them?
>
> Yes, that's a better idea.

How about putting all methods that depend on read into a module
ReadMixin (another better name for it?). For readbytes.rb this would
look like:

It was exactly what I wrote, except for the name. I thought
IO::Readable and IO::Writable instead.

···

--
Nobu Nakada

yay for Readable and Writable!!
Maybe it's time to revisit RCR65 ?
Nobu, do you think that this could fit in the ruby core?

···

il Mon, 12 Jul 2004 10:22:21 +0900, nobu.nokada@softhome.net ha scritto::

How about putting all methods that depend on read into a module
ReadMixin (another better name for it?). For readbytes.rb this would
look like:

It was exactly what I wrote, except for the name. I thought
IO::Readable and IO::Writable instead.

Hi,

At Mon, 12 Jul 2004 15:57:35 +0900,
gabriele renzi wrote in [ruby-talk:106051]:

yay for Readable and Writable!!

I fetched those names from the thread from [ruby-dev:15830],
though they weren't in IO and Matz didn't like them.

Maybe it's time to revisit RCR65 ?
Nobu, do you think that this could fit in the ruby core?

I couldn't find RCR65. One of the legacy RCR's?

···

--
Nobu Nakada

it is here:
http://www.rcrchive.net/rgarchive/rejected.html#rcr65

···

il Tue, 13 Jul 2004 16:04:12 +0900, nobu.nokada@softhome.net ha scritto::

Hi,

At Mon, 12 Jul 2004 15:57:35 +0900,
gabriele renzi wrote in [ruby-talk:106051]:

yay for Readable and Writable!!

I fetched those names from the thread from [ruby-dev:15830],
though they weren't in IO and Matz didn't like them.

Maybe it's time to revisit RCR65 ?
Nobu, do you think that this could fit in the ruby core?

I couldn't find RCR65. One of the legacy RCR's?