diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-21 08:48:33 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-21 08:48:33 +0000 |
commit | ffc456d0ed1acf478ff991c88e35b2038dccb402 (patch) | |
tree | 847b4cfc16cc66aac40816b9e9769ffb64f95794 /ext/stringio/stringio.c | |
parent | eeceb720a9589bd9a0acf47db9da05668d7a5865 (diff) | |
download | ruby-ffc456d0ed1acf478ff991c88e35b2038dccb402.tar.gz |
* ext/dbm/dbm.c (fdbm_each_value, fdbm_each_key, fdbm_each_pair):
GDBM#{each,each_pair,each_key,each_value}: Return an enumerator
if no block is given.
* ext/gdbm/gdbm.c (fgdbm_each_value, fgdbm_each_key,
fgdbm_each_pair): GDBM#{each,each_pair,each_key,each_value}:
Return an enumerator if no block is given.
* ext/openssl/ossl_config.c (ossl_config_each):
OpenSSL::Config#each: Return an enumerator if no block is given.
* ext/readline/readline.c (hist_each): Readline::HISTORY#each:
Return an enumerator if no block is given.
* ext/sdbm/init.c (fsdbm_each_value, fsdbm_each_key,
fsdbm_each_pair): SDBM#{each,each_pair,each_key,each_value}:
Return an enumerator if no block is given.
* ext/stringio/stringio.c (strio_each_byte, strio_each):
StringIO#{each,each_line,each_byte}: Return an enumerator if no
block is given.
* ext/stringio/stringio.c (Init_stringio): Add #lines and #bytes,
which are aliases to #each_line and #each_byte, respectively.
* ext/win32ole/win32ole.c (fole_each): WIN32OLE#each: Return an
enumerator if no block is given.
* ext/zlib/zlib.c (rb_gzreader_each_byte, rb_gzreader_each):
Zlib::GzipReader#{each,each_line,each_byte}: Return an
enumerator if no block is given.
* ext/zlib/zlib.c (Init_zlib): Add Zlib::GzipReader#lines and
#bytes, which are aliases to #each_line and #each_byte,
respectively.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/stringio/stringio.c')
-rw-r--r-- | ext/stringio/stringio.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 6b867084df..fc589ef55d 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -614,6 +614,9 @@ static VALUE strio_each_byte(VALUE self) { struct StringIO *ptr = readable(StringIO(self)); + + RETURN_ENUMERATOR(self, 0, 0); + while (ptr->pos < RSTRING_LEN(ptr->string)) { char c = RSTRING_PTR(ptr->string)[ptr->pos++]; rb_yield(CHR2FIX(c)); @@ -926,6 +929,8 @@ strio_each(int argc, VALUE *argv, VALUE 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); } @@ -1233,7 +1238,9 @@ Init_stringio() rb_define_method(StringIO, "each", strio_each, -1); rb_define_method(StringIO, "each_byte", strio_each_byte, 0); + rb_define_method(StringIO, "bytes", strio_each_byte, -1); rb_define_method(StringIO, "each_line", strio_each, -1); + rb_define_method(StringIO, "lines", strio_each, -1); rb_define_method(StringIO, "getc", strio_getc, 0); rb_define_method(StringIO, "ungetc", strio_ungetc, 1); rb_define_method(StringIO, "readchar", strio_readchar, 0); |