ruby-changes:5137
From: knu <ko1@a...>
Date: Tue, 27 May 2008 18:16:38 +0900 (JST)
Subject: [ruby-changes:5137] Ruby:r16632 (ruby_1_8): * ext/stringio/stringio.c (strio_each): Return an enumerator if no
knu 2008-05-27 18:16:11 +0900 (Tue, 27 May 2008)
New Revision: 16632
Modified files:
branches/ruby_1_8/ChangeLog
branches/ruby_1_8/NEWS
branches/ruby_1_8/ext/stringio/stringio.c
branches/ruby_1_8/io.c
Log:
* ext/stringio/stringio.c (strio_each): Return an enumerator if no
block is given.
(strio_each_byte): Return an enumerator if no block is given,
and return self if one is given as the rdoc says.
* io.c (rb_io_each_byte): Fix rdoc. IO#each_byte returns self,
not nil.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=16632&r2=16631&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ext/stringio/stringio.c?r1=16632&r2=16631&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/io.c?r1=16632&r2=16631&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/NEWS?r1=16632&r2=16631&diff_format=u
Index: ruby_1_8/ext/stringio/stringio.c
===================================================================
--- ruby_1_8/ext/stringio/stringio.c (revision 16631)
+++ ruby_1_8/ext/stringio/stringio.c (revision 16632)
@@ -710,11 +710,14 @@
VALUE self;
{
struct StringIO *ptr = readable(StringIO(self));
- while (ptr->pos < RSTRING(ptr->string)->len) {
- char c = RSTRING(ptr->string)->ptr[ptr->pos++];
+
+ RETURN_ENUMERATOR(self, 0, 0);
+
+ while (ptr->pos < RSTRING_LEN(ptr->string)) {
+ char c = RSTRING_PTR(ptr->string)[ptr->pos++];
rb_yield(CHR2FIX(c));
}
- return Qnil;
+ return self;
}
/*
@@ -971,6 +974,8 @@
struct StringIO *ptr = StringIO(self);
VALUE line;
+ RETURN_ENUMERATOR(self, argc, argv);
+
while (!NIL_P(line = strio_getline(argc, argv, readable(ptr)))) {
rb_yield(line);
}
Index: ruby_1_8/NEWS
===================================================================
--- ruby_1_8/NEWS (revision 16631)
+++ ruby_1_8/NEWS (revision 16632)
@@ -328,12 +328,17 @@
* stringio
- * Add new methods. (aliases for compatibility with 1.9)
+ * StringIO#getbyte
+ * StringIO#readbyte
- * StringIO#getbyte
- * StringIO#readbyte
+ Add new methods. (aliases for compatibility with 1.9)
+ * StringIO#each
+ * StringIO#each_line
+ * StringIO#each_byte
+ Return an enumerator if no block is given.
+
* tempfile
* Tempfile.open and Tempfile.new now accept a suffix for the
@@ -412,6 +417,13 @@
always use Date.strptime() when you know what you are dealing
with.
+* stringio
+
+ * StringIO#each_byte
+
+ The return value changed from nil to self. This is what the
+ document says and the same as each_line() does.
+
* tempfile
* The file name format has changed. No dots are included by default
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog (revision 16631)
+++ ruby_1_8/ChangeLog (revision 16632)
@@ -1,3 +1,13 @@
+Tue May 27 17:59:34 2008 Akinori MUSHA <knu@i...>
+
+ * ext/stringio/stringio.c (strio_each): Return an enumerator if no
+ block is given.
+ (strio_each_byte): Return an enumerator if no block is given,
+ and return self if one is given as the rdoc says.
+
+ * io.c (rb_io_each_byte): Fix rdoc. IO#each_byte returns self,
+ not nil.
+
Tue May 27 16:02:58 2008 Akinori MUSHA <knu@i...>
* eval.c (rb_mod_module_exec, Init_eval): Add
Index: ruby_1_8/io.c
===================================================================
--- ruby_1_8/io.c (revision 16631)
+++ ruby_1_8/io.c (revision 16632)
@@ -1981,7 +1981,7 @@
/*
* call-seq:
- * ios.each_byte {|byte| block } => nil
+ * ios.each_byte {|byte| block } => ios
*
* Calls the given block once for each byte (0..255) in <em>ios</em>,
* passing the byte as an argument. The stream must be opened for
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/