StringIO#readbytes

  • Thread starter Michael Neumann
  • Start date
M

Michael Neumann

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
 
N

nobu.nokada

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?
 
M

Michael Neumann

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
 
M

Michael Neumann

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.

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
 
N

nobu.nokada

Hi,

At Mon, 12 Jul 2004 02:58:34 +0900,
Michael Neumann wrote in [ruby-talk:106007]:
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.
 
G

gabriele renzi

il Mon, 12 Jul 2004 10:22:21 +0900, (e-mail address removed) ha
scritto::
It was exactly what I wrote, except for the name. I thought
IO::Readable and IO::Writable instead.

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

nobu.nokada

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?
 
G

gabriele renzi

il Tue, 13 Jul 2004 16:04:12 +0900, (e-mail address removed) 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?

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,147
Messages
2,570,833
Members
47,380
Latest member
AlinaBlevi

Latest Threads

Top