1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16632 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2008-05-27 09:16:11 +00:00
parent 266be04a8d
commit e37b7b77a8
4 changed files with 34 additions and 7 deletions

View file

@ -1,3 +1,13 @@
Tue May 27 17:59:34 2008 Akinori MUSHA <knu@iDaemons.org>
* 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@iDaemons.org>
* eval.c (rb_mod_module_exec, Init_eval): Add

18
NEWS
View file

@ -328,11 +328,16 @@ with all sufficient information, see the ChangeLog file.
* 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
@ -412,6 +417,13 @@ with all sufficient information, see the ChangeLog file.
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

View file

@ -710,11 +710,14 @@ strio_each_byte(self)
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 @@ strio_each(argc, argv, self)
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);
}

2
io.c
View file

@ -1981,7 +1981,7 @@ rb_io_each_line(argc, argv, io)
/*
* 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