ruby-changes:5128
From: knu <ko1@a...>
Date: Tue, 27 May 2008 13:23:06 +0900 (JST)
Subject: [ruby-changes:5128] Ruby:r16623 (ruby_1_8): * io.c: (rb_io_lines, rb_io_bytes, Init_IO): Define
knu 2008-05-27 13:22:56 +0900 (Tue, 27 May 2008)
New Revision: 16623
Modified files:
branches/ruby_1_8/ChangeLog
branches/ruby_1_8/NEWS
branches/ruby_1_8/io.c
Log:
* io.c: (rb_io_lines, rb_io_bytes, Init_IO): Define
IO#{lines,bytes} and ARGF.{lines,bytes}.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=16623&r2=16622&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/io.c?r1=16623&r2=16622&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/NEWS?r1=16623&r2=16622&diff_format=u
Index: ruby_1_8/NEWS
===================================================================
--- ruby_1_8/NEWS (revision 16622)
+++ ruby_1_8/NEWS (revision 16623)
@@ -171,10 +171,14 @@
* IO#each
* IO#each_line
* IO#each_byte
+ * IO#lines
+ * IO#bytes
* IO.foreach
* ARGF.each
* ARGF.each_line
* ARGF.each_byte
+ * ARGF.lines
+ * ARGF.bytes
Return an enumerator if no block is given.
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog (revision 16622)
+++ ruby_1_8/ChangeLog (revision 16623)
@@ -1,3 +1,8 @@
+Tue May 27 13:20:35 2008 Akinori MUSHA <knu@i...>
+
+ * io.c: (rb_io_lines, rb_io_bytes, Init_IO): Define
+ IO#{lines,bytes} and ARGF.{lines,bytes}.
+
Tue May 27 12:13:17 2008 NAKAMURA Usaku <usa@r...>
* file.c (BUFCHECK): wrong condition. [ruby-core:16921]
Index: ruby_1_8/io.c
===================================================================
--- ruby_1_8/io.c (revision 16622)
+++ ruby_1_8/io.c (revision 16623)
@@ -2028,6 +2028,52 @@
/*
* 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(argc, argv, io)
+ 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(io)
+ VALUE io;
+{
+ return rb_enumeratorize(io, ID2SYM(rb_intern("each_byte")), 0, 0);
+}
+
+/*
+ * call-seq:
* ios.getc => fixnum or nil
*
* Gets the next 8-bit byte (0..255) from <em>ios</em>. Returns
@@ -5808,6 +5854,8 @@
rb_define_method(rb_cIO, "each", rb_io_each_line, -1);
rb_define_method(rb_cIO, "each_line", rb_io_each_line, -1);
rb_define_method(rb_cIO, "each_byte", rb_io_each_byte, 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, "syswrite", rb_io_syswrite, 1);
rb_define_method(rb_cIO, "sysread", rb_io_sysread, -1);
@@ -5895,6 +5943,8 @@
rb_define_singleton_method(argf, "each", argf_each_line, -1);
rb_define_singleton_method(argf, "each_line", argf_each_line, -1);
rb_define_singleton_method(argf, "each_byte", argf_each_byte, 0);
+ rb_define_singleton_method(argf, "lines", argf_lines, -1);
+ rb_define_singleton_method(argf, "bytes", argf_bytes, 0);
rb_define_singleton_method(argf, "read", argf_read, -1);
rb_define_singleton_method(argf, "readlines", rb_f_readlines, -1);
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/