summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-22 17:22:04 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-22 17:22:04 +0000
commitc47c095b9740e7c19d6fdca29ab661c1089221d4 (patch)
tree6a8204e2977b6743db056b348b2167cdbc11a06b /io.c
parent2742b6bc432e82a502a7fe7234090592a31dc432 (diff)
Deprecate #{lines,bytes,chars,codepoints} of IO-likes.
* io.c (rb_io_lines, rb_io_bytes, rb_io_chars, rb_io_codepoints): Deprecate IO#{lines,bytes,chars,codepoints} and those of ARGF. [Feature #6670] * ext/stringio/stringio.c (strio_lines, strio_bytes, strio_chars) (strio_codepoints): Deprecate StringIO#{lines,bytes,chars,codepoints}. [Feature #6670] * ext/zlib/zlib.c (rb_gzreader_lines, rb_gzreader_bytes): Deprecate Zlib::GzipReader#{lines,bytes}. [Feature #6670] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38563 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c140
1 files changed, 111 insertions, 29 deletions
diff --git a/io.c b/io.c
index 9d124c00e9..53539da7b5 100644
--- a/io.c
+++ b/io.c
@@ -3216,11 +3216,6 @@ rb_io_readlines(int argc, VALUE *argv, VALUE io)
* ios.each_line(sep,limit) {|line| block } -> ios
* ios.each_line(...) -> an_enumerator
*
- * ios.lines(sep=$/) {|line| block } -> ios
- * ios.lines(limit) {|line| block } -> ios
- * ios.lines(sep,limit) {|line| block } -> ios
- * ios.lines(...) -> an_enumerator
- *
* Executes the block for every line in <em>ios</em>, where lines are
* separated by <i>sep</i>. <em>ios</em> must be opened for
* reading or an <code>IOError</code> will be raised.
@@ -3255,10 +3250,20 @@ rb_io_each_line(int argc, VALUE *argv, VALUE io)
}
/*
+ * This is a deprecated alias for <code>each_line</code>.
+ */
+
+static VALUE
+rb_io_lines(int argc, VALUE *argv, VALUE io)
+{
+ rb_warn("IO#lines is deprecated; use #each_line instead");
+ if (!rb_block_given_p())
+ return rb_enumeratorize(io, ID2SYM(rb_intern("each_line")), argc, argv);
+ return rb_io_each_line(argc, argv, io);
+}
+
+/*
* call-seq:
- * ios.bytes {|byte| block } -> ios
- * ios.bytes -> an_enumerator
- *
* ios.each_byte {|byte| block } -> ios
* ios.each_byte -> an_enumerator
*
@@ -3298,6 +3303,19 @@ rb_io_each_byte(VALUE io)
return io;
}
+/*
+ * This is a deprecated alias for <code>each_byte</code>.
+ */
+
+static VALUE
+rb_io_bytes(VALUE io)
+{
+ rb_warn("IO#bytes is deprecated; use #each_byte instead");
+ if (!rb_block_given_p())
+ return rb_enumeratorize(io, ID2SYM(rb_intern("each_byte")), 0, 0);
+ return rb_io_each_byte(io);
+}
+
static VALUE
io_getc(rb_io_t *fptr, rb_encoding *enc)
{
@@ -3403,9 +3421,6 @@ io_getc(rb_io_t *fptr, rb_encoding *enc)
/*
* call-seq:
- * ios.chars {|c| block } -> ios
- * ios.chars -> an_enumerator
- *
* ios.each_char {|c| block } -> ios
* ios.each_char -> an_enumerator
*
@@ -3438,6 +3453,19 @@ rb_io_each_char(VALUE io)
return io;
}
+/*
+ * This is a deprecated alias for <code>each_char</code>.
+ */
+
+static VALUE
+rb_io_chars(VALUE io)
+{
+ rb_warn("IO#chars is deprecated; use #each_char instead");
+ if (!rb_block_given_p())
+ return rb_enumeratorize(io, ID2SYM(rb_intern("each_char")), 0, 0);
+ return rb_io_each_char(io);
+}
+
/*
* call-seq:
@@ -3535,6 +3563,18 @@ rb_io_each_codepoint(VALUE io)
return io;
}
+/*
+ * This is a deprecated alias for <code>each_codepoint</code>.
+ */
+
+static VALUE
+rb_io_codepoints(VALUE io)
+{
+ rb_warn("IO#codepoints is deprecated; use #each_codepoint instead");
+ if (!rb_block_given_p())
+ return rb_enumeratorize(io, ID2SYM(rb_intern("each_codepoint")), 0, 0);
+ return rb_io_each_codepoint(io);
+}
/*
@@ -10844,10 +10884,6 @@ argf_readbyte(VALUE argf)
* ARGF.each_line(sep=$/,limit) {|line| block } -> ARGF
* ARGF.each_line(...) -> an_enumerator
*
- * ARGF.lines(sep=$/) {|line| block } -> ARGF
- * ARGF.lines(sep=$/,limit) {|line| block } -> ARGF
- * ARGF.lines(...) -> an_enumerator
- *
* Returns an enumerator which iterates over each line (separated by _sep_,
* which defaults to your platform's newline character) of each file in
* +ARGV+. If a block is supplied, each line in turn will be yielded to the
@@ -10882,6 +10918,19 @@ argf_each_line(int argc, VALUE *argv, VALUE argf)
}
/*
+ * This is a deprecated alias for <code>each_line</code>.
+ */
+
+static VALUE
+argf_lines(int argc, VALUE *argv, VALUE argf)
+{
+ rb_warn("ARGF#lines is deprecated; use #each_line instead");
+ if (!rb_block_given_p())
+ return rb_enumeratorize(argf, ID2SYM(rb_intern("each_line")), argc, argv);
+ return argf_each_line(argc, argv, argf);
+}
+
+/*
* call-seq:
* ARGF.bytes {|byte| block } -> ARGF
* ARGF.bytes -> an_enumerator
@@ -10917,10 +10966,20 @@ argf_each_byte(VALUE argf)
}
/*
+ * This is a deprecated alias for <code>each_byte</code>.
+ */
+
+static VALUE
+argf_bytes(VALUE argf)
+{
+ rb_warn("ARGF#bytes is deprecated; use #each_byte instead");
+ if (!rb_block_given_p())
+ return rb_enumeratorize(argf, ID2SYM(rb_intern("each_byte")), 0, 0);
+ return argf_each_byte(argf);
+}
+
+/*
* call-seq:
- * ARGF.chars {|char| block } -> ARGF
- * ARGF.chars -> an_enumerator
- *
* ARGF.each_char {|char| block } -> ARGF
* ARGF.each_char -> an_enumerator
*
@@ -10947,10 +11006,20 @@ argf_each_char(VALUE argf)
}
/*
+ * This is a deprecated alias for <code>each_char</code>.
+ */
+
+static VALUE
+argf_chars(VALUE argf)
+{
+ rb_warn("ARGF#chars is deprecated; use #each_char instead");
+ if (!rb_block_given_p())
+ return rb_enumeratorize(argf, ID2SYM(rb_intern("each_char")), 0, 0);
+ return argf_each_char(argf);
+}
+
+/*
* call-seq:
- * ARGF.codepoints {|codepoint| block } -> ARGF
- * ARGF.codepoints -> an_enumerator
- *
* ARGF.each_codepoint {|codepoint| block } -> ARGF
* ARGF.each_codepoint -> an_enumerator
*
@@ -10977,6 +11046,19 @@ argf_each_codepoint(VALUE argf)
}
/*
+ * This is a deprecated alias for <code>each_codepoint</code>.
+ */
+
+static VALUE
+argf_codepoints(VALUE argf)
+{
+ rb_warn("ARGF#codepoints is deprecated; use #each_codepoint instead");
+ if (!rb_block_given_p())
+ return rb_enumeratorize(argf, ID2SYM(rb_intern("each_codepoint")), 0, 0);
+ return argf_each_codepoint(argf);
+}
+
+/*
* call-seq:
* ARGF.filename -> String
* ARGF.path -> String
@@ -11556,10 +11638,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_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, "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, "syswrite", rb_io_syswrite, 1);
rb_define_method(rb_cIO, "sysread", rb_io_sysread, -1);
@@ -11674,10 +11756,10 @@ Init_IO(void)
rb_define_method(rb_cARGF, "each_byte", argf_each_byte, 0);
rb_define_method(rb_cARGF, "each_char", argf_each_char, 0);
rb_define_method(rb_cARGF, "each_codepoint", argf_each_codepoint, 0);
- rb_define_method(rb_cARGF, "lines", argf_each_line, -1);
- rb_define_method(rb_cARGF, "bytes", argf_each_byte, 0);
- rb_define_method(rb_cARGF, "chars", argf_each_char, 0);
- rb_define_method(rb_cARGF, "codepoints", argf_each_codepoint, 0);
+ rb_define_method(rb_cARGF, "lines", argf_lines, -1);
+ rb_define_method(rb_cARGF, "bytes", argf_bytes, 0);
+ rb_define_method(rb_cARGF, "chars", argf_chars, 0);
+ rb_define_method(rb_cARGF, "codepoints", argf_codepoints, 0);
rb_define_method(rb_cARGF, "read", argf_read, -1);
rb_define_method(rb_cARGF, "readpartial", argf_readpartial, -1);