From c47c095b9740e7c19d6fdca29ab661c1089221d4 Mon Sep 17 00:00:00 2001 From: knu Date: Sat, 22 Dec 2012 17:22:04 +0000 Subject: 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 --- io.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 111 insertions(+), 29 deletions(-) (limited to 'io.c') 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 ios, where lines are * separated by sep. ios must be opened for * reading or an IOError will be raised. @@ -3254,11 +3249,21 @@ rb_io_each_line(int argc, VALUE *argv, VALUE io) return io; } +/* + * This is a deprecated alias for each_line. + */ + +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 each_byte. + */ + +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 each_char. + */ + +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 each_codepoint. + */ + +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 @@ -10881,6 +10917,19 @@ argf_each_line(int argc, VALUE *argv, VALUE argf) } } +/* + * This is a deprecated alias for each_line. + */ + +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 @@ -10916,11 +10965,21 @@ argf_each_byte(VALUE argf) } } +/* + * This is a deprecated alias for each_byte. + */ + +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 * @@ -10946,11 +11005,21 @@ argf_each_char(VALUE argf) } } +/* + * This is a deprecated alias for each_char. + */ + +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 * @@ -10976,6 +11045,19 @@ argf_each_codepoint(VALUE argf) } } +/* + * This is a deprecated alias for each_codepoint. + */ + +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 @@ -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); -- cgit v1.2.3