[前][次][番号順一覧][スレッド一覧]

ruby-changes:14927

From: mame <ko1@a...>
Date: Tue, 2 Mar 2010 21:19:43 +0900 (JST)
Subject: [ruby-changes:14927] Ruby:r26797 (trunk): * io.c (rb_io_lines, rb_io_bytes, rb_io_chars, rb_io_codepoints):

mame	2010-03-02 21:19:24 +0900 (Tue, 02 Mar 2010)

  New Revision: 26797

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26797

  Log:
    * 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]

  Modified files:
    trunk/ChangeLog
    trunk/io.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26796)
+++ ChangeLog	(revision 26797)
@@ -1,3 +1,9 @@
+Tue Mar  2 21:16:48 2010  Yusuke Endoh  <mame@t...>
+
+	* 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@r...>
 
 	* regcomp.c (noname_disable_map): add NT_ANCHOR case.
Index: io.c
===================================================================
--- io.c	(revision 26796)
+++ io.c	(revision 26797)
@@ -2613,6 +2613,22 @@
 
 /*
  *  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
  *     ios.each(limit) {|line| block }          => ios
  *     ios.each(sep,limit) {|line| block }      => ios
@@ -2651,6 +2667,20 @@
 
 /*
  *  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
  *
  *  Calls the given block once for each byte (0..255) in <em>ios</em>,
@@ -2783,6 +2813,20 @@
 
 /*
  *  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
  *
  *  Calls the given block once for each character in <em>ios</em>,
@@ -2816,6 +2860,15 @@
 
 /*
  *  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
  *
  *  Passes the <code>Integer</code> ordinal of each character in <i>ios</i>,
@@ -2901,83 +2954,6 @@
 
 /*
  *  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
  *
  *  Reads a one-character string from <em>ios</em>. Returns
@@ -9764,10 +9740,10 @@
     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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]