* io.c (rb_io_lines, rb_io_bytes, rb_io_chars, rb_io_codepoints):

change to alias to each_*, in similar way to ARGF and String.
  [ruby-core:23948]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2010-03-02 12:19:24 +00:00
Родитель 76a5c00be6
Коммит a0ff5cae7c
2 изменённых файлов: 63 добавлений и 81 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Tue Mar 2 21:16:48 2010 Yusuke Endoh <mame@tsg.ne.jp>
* io.c (rb_io_lines, rb_io_bytes, rb_io_chars, rb_io_codepoints):
change to alias to each_*, in similar way to ARGF and String.
[ruby-core:23948]
Tue Mar 2 15:54:40 2010 NARUSE, Yui <naruse@ruby-lang.org>
* regcomp.c (noname_disable_map): add NT_ANCHOR case.

138
io.c
Просмотреть файл

@ -2611,6 +2611,22 @@ rb_io_readlines(int argc, VALUE *argv, VALUE io)
return ary;
}
/*
* call-seq:
* ios.lines(sep=$/) => anEnumerator
* ios.lines(limit) => anEnumerator
* ios.lines(sep, limit) => anEnumerator
*
* Returns an enumerator that gives each line in <em>ios</em>.
* The stream must be opened for reading or an <code>IOError</code>
* will be raised.
*
* f = File.new("testfile")
* f.lines.to_a #=> ["foo\n", "bar\n"]
* f.rewind
* f.lines.sort #=> ["bar\n", "foo\n"]
*/
/*
* call-seq:
* ios.each(sep=$/) {|line| block } => ios
@ -2649,6 +2665,20 @@ rb_io_each_line(int argc, VALUE *argv, VALUE io)
return io;
}
/*
* call-seq:
* ios.bytes => anEnumerator
*
* Returns an enumerator that gives each byte (0..255) in <em>ios</em>.
* The stream must be opened for reading or an <code>IOError</code>
* will be raised.
*
* f = File.new("testfile")
* f.bytes.to_a #=> [104, 101, 108, 108, 111]
* f.rewind
* f.bytes.sort #=> [101, 104, 108, 108, 111]
*/
/*
* call-seq:
* ios.each_byte {|byte| block } => ios
@ -2781,6 +2811,20 @@ io_getc(rb_io_t *fptr, rb_encoding *enc)
return str;
}
/*
* call-seq:
* ios.chars => anEnumerator
*
* Returns an enumerator that gives each character in <em>ios</em>.
* The stream must be opened for reading or an <code>IOError</code>
* will be raised.
*
* f = File.new("testfile")
* f.chars.to_a #=> ["h", "e", "l", "l", "o"]
* f.rewind
* f.chars.sort #=> ["e", "h", "l", "l", "o"]
*/
/*
* call-seq:
* ios.each_char {|c| block } => ios
@ -2814,6 +2858,15 @@ rb_io_each_char(VALUE io)
/*
* call-seq:
* ios.codepoints => anEnumerator
*
* Returns an enumerator that gives each codepoint in <em>ios</em>.
* The stream must be opened for reading or an <code>IOError</code>
* will be raised.
*/
/*
* call-seq:
* ios.each_codepoint {|c| block } => ios
@ -2899,83 +2952,6 @@ rb_io_each_codepoint(VALUE io)
/*
* call-seq:
* ios.lines(sep=$/) => anEnumerator
* ios.lines(limit) => anEnumerator
* ios.lines(sep, limit) => anEnumerator
*
* Returns an enumerator that gives each line in <em>ios</em>.
* The stream must be opened for reading or an <code>IOError</code>
* will be raised.
*
* f = File.new("testfile")
* f.lines.to_a #=> ["foo\n", "bar\n"]
* f.rewind
* f.lines.sort #=> ["bar\n", "foo\n"]
*/
static VALUE
rb_io_lines(int argc, VALUE *argv, VALUE io)
{
return rb_enumeratorize(io, ID2SYM(rb_intern("each_line")), argc, argv);
}
/*
* call-seq:
* ios.bytes => anEnumerator
*
* Returns an enumerator that gives each byte (0..255) in <em>ios</em>.
* The stream must be opened for reading or an <code>IOError</code>
* will be raised.
*
* f = File.new("testfile")
* f.bytes.to_a #=> [104, 101, 108, 108, 111]
* f.rewind
* f.bytes.sort #=> [101, 104, 108, 108, 111]
*/
static VALUE
rb_io_bytes(VALUE io)
{
return rb_enumeratorize(io, ID2SYM(rb_intern("each_byte")), 0, 0);
}
/*
* call-seq:
* ios.chars => anEnumerator
*
* Returns an enumerator that gives each character in <em>ios</em>.
* The stream must be opened for reading or an <code>IOError</code>
* will be raised.
*
* f = File.new("testfile")
* f.chars.to_a #=> ["h", "e", "l", "l", "o"]
* f.rewind
* f.chars.sort #=> ["e", "h", "l", "l", "o"]
*/
static VALUE
rb_io_chars(VALUE io)
{
return rb_enumeratorize(io, ID2SYM(rb_intern("each_char")), 0, 0);
}
/*
* call-seq:
* ios.codepoints => anEnumerator
*
* Returns an enumerator that gives each codepoint in <em>ios</em>.
* The stream must be opened for reading or an <code>IOError</code>
* will be raised.
*/
static VALUE
rb_io_codepoints(VALUE io)
{
return rb_enumeratorize(io, ID2SYM(rb_intern("each_codepoint")), 0, 0);
}
/*
* call-seq:
* ios.getc => string or nil
@ -9764,10 +9740,10 @@ Init_IO(void)
rb_define_method(rb_cIO, "each_byte", rb_io_each_byte, 0);
rb_define_method(rb_cIO, "each_char", rb_io_each_char, 0);
rb_define_method(rb_cIO, "each_codepoint", rb_io_each_codepoint, 0);
rb_define_method(rb_cIO, "lines", rb_io_lines, -1);
rb_define_method(rb_cIO, "bytes", rb_io_bytes, 0);
rb_define_method(rb_cIO, "chars", rb_io_chars, 0);
rb_define_method(rb_cIO, "codepoints", rb_io_codepoints, 0);
rb_define_method(rb_cIO, "lines", rb_io_each_line, -1);
rb_define_method(rb_cIO, "bytes", rb_io_each_byte, 0);
rb_define_method(rb_cIO, "chars", rb_io_each_char, 0);
rb_define_method(rb_cIO, "codepoints", rb_io_each_codepoint, 0);
rb_define_method(rb_cIO, "syswrite", rb_io_syswrite, 1);
rb_define_method(rb_cIO, "sysread", rb_io_sysread, -1);