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 --- ext/stringio/stringio.c | 70 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 18 deletions(-) (limited to 'ext/stringio') diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 975a30855f..d763854faf 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -630,9 +630,6 @@ strio_get_sync(VALUE self) /* * call-seq: - * strio.bytes {|byte| block } -> strio - * strio.bytes -> anEnumerator - * * strio.each_byte {|byte| block } -> strio * strio.each_byte -> anEnumerator * @@ -652,6 +649,18 @@ strio_each_byte(VALUE self) return self; } +/* + * This is a deprecated alias for each_byte. + */ +static VALUE +strio_bytes(VALUE self) +{ + rb_warn("StringIO#bytes is deprecated; use #each_byte instead"); + if (!rb_block_given_p()) + return rb_enumeratorize(self, ID2SYM(rb_intern("each_byte")), 0, 0); + return strio_each_byte(self); +} + /* * call-seq: * strio.getc -> string or nil @@ -840,9 +849,6 @@ strio_readbyte(VALUE self) /* * call-seq: - * strio.chars {|char| block } -> strio - * strio.chars -> anEnumerator - * * strio.each_char {|char| block } -> strio * strio.each_char -> anEnumerator * @@ -861,11 +867,20 @@ strio_each_char(VALUE self) return self; } +/* + * This is a deprecated alias for each_char. + */ +static VALUE +strio_chars(VALUE self) +{ + rb_warn("StringIO#chars is deprecated; use #each_char instead"); + if (!rb_block_given_p()) + return rb_enumeratorize(self, ID2SYM(rb_intern("each_char")), 0, 0); + return strio_each_char(self); +} + /* * call-seq: - * strio.codepoints {|c| block } -> strio - * strio.codepoints -> anEnumerator - * * strio.each_codepoint {|c| block } -> strio * strio.each_codepoint -> anEnumerator * @@ -896,6 +911,18 @@ strio_each_codepoint(VALUE self) return self; } +/* + * This is a deprecated alias for each_codepoint. + */ +static VALUE +strio_codepoints(VALUE self) +{ + rb_warn("StringIO#codepoints is deprecated; use #each_codepoint instead"); + if (!rb_block_given_p()) + return rb_enumeratorize(self, ID2SYM(rb_intern("each_codepoint")), 0, 0); + return strio_each_codepoint(self); +} + /* Boyer-Moore search: copied from regex.c */ static void bm_init_skip(long *skip, const char *pat, long m) @@ -1067,11 +1094,6 @@ strio_readline(int argc, VALUE *argv, VALUE self) * strio.each_line(sep,limit) {|line| block } -> strio * strio.each_line(...) -> anEnumerator * - * strio.lines(sep=$/) {|line| block } -> strio - * strio.lines(limit) {|line| block } -> strio - * strio.lines(sep,limit) {|line| block } -> strio - * strio.lines(...) -> anEnumerator - * * See IO#each. */ static VALUE @@ -1093,6 +1115,18 @@ strio_each(int argc, VALUE *argv, VALUE self) return self; } +/* + * This is a deprecated alias for each_line. + */ +static VALUE +strio_lines(int argc, VALUE *argv, VALUE self) +{ + rb_warn("StringIO#lines is deprecated; use #each_line instead"); + if (!rb_block_given_p()) + return rb_enumeratorize(self, ID2SYM(rb_intern("each_line")), argc, argv); + return strio_each(argc, argv, self); +} + /* * call-seq: * strio.readlines(sep=$/) -> array @@ -1463,13 +1497,13 @@ Init_stringio() rb_define_method(StringIO, "each", strio_each, -1); rb_define_method(StringIO, "each_line", strio_each, -1); - rb_define_method(StringIO, "lines", strio_each, -1); + rb_define_method(StringIO, "lines", strio_lines, -1); rb_define_method(StringIO, "each_byte", strio_each_byte, 0); - rb_define_method(StringIO, "bytes", strio_each_byte, 0); + rb_define_method(StringIO, "bytes", strio_bytes, 0); rb_define_method(StringIO, "each_char", strio_each_char, 0); - rb_define_method(StringIO, "chars", strio_each_char, 0); + rb_define_method(StringIO, "chars", strio_chars, 0); rb_define_method(StringIO, "each_codepoint", strio_each_codepoint, 0); - rb_define_method(StringIO, "codepoints", strio_each_codepoint, 0); + rb_define_method(StringIO, "codepoints", strio_codepoints, 0); rb_define_method(StringIO, "getc", strio_getc, 0); rb_define_method(StringIO, "ungetc", strio_ungetc, 1); rb_define_method(StringIO, "ungetbyte", strio_ungetbyte, 1); -- cgit v1.2.3