summaryrefslogtreecommitdiff
path: root/ext/stringio/stringio.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 /ext/stringio/stringio.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 'ext/stringio/stringio.c')
-rw-r--r--ext/stringio/stringio.c70
1 files changed, 52 insertions, 18 deletions
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
*
@@ -653,6 +650,18 @@ strio_each_byte(VALUE self)
}
/*
+ * This is a deprecated alias for <code>each_byte</code>.
+ */
+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
*
@@ -862,10 +868,19 @@ strio_each_char(VALUE self)
}
/*
+ * This is a deprecated alias for <code>each_char</code>.
+ */
+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 <code>each_codepoint</code>.
+ */
+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
@@ -1094,6 +1116,18 @@ strio_each(int argc, VALUE *argv, VALUE self)
}
/*
+ * This is a deprecated alias for <code>each_line</code>.
+ */
+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
* strio.readlines(limit) -> 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);