summaryrefslogtreecommitdiff
path: root/ext/stringio
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-27 06:47:56 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-27 06:47:56 (GMT)
commit7a5b56677a075677439fbfc61025ddf93ca708f8 (patch)
treed9897bde3b61eed064dbf177e425adcfe0b9883c /ext/stringio
parentd226ce8decef356c7447efb6b6b325bc8fc53dba (diff)
stringio.c: warn block for new
* ext/stringio/stringio.c (strio_s_new): warn if a block is given, as well as IO.new. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/stringio')
-rw-r--r--ext/stringio/stringio.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index bd83ea2..368dcfe 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -241,6 +241,19 @@ strio_s_open(int argc, VALUE *argv, VALUE klass)
return rb_ensure(rb_yield, obj, strio_finalize, obj);
}
+/* :nodoc: */
+static VALUE
+strio_s_new(int argc, VALUE *argv, VALUE klass)
+{
+ if (rb_block_given_p()) {
+ VALUE cname = rb_obj_as_string(klass);
+
+ rb_warn("%"PRIsVALUE"::new() does not take block; use %"PRIsVALUE"::open() instead",
+ cname, cname);
+ }
+ return rb_class_new_instance(argc, argv, klass);
+}
+
/*
* Returns +false+. Just for compatibility to IO.
*/
@@ -1523,6 +1536,7 @@ Init_stringio(void)
rb_include_module(StringIO, rb_mEnumerable);
rb_define_alloc_func(StringIO, strio_s_allocate);
+ rb_define_singleton_method(StringIO, "new", strio_s_new, -1);
rb_define_singleton_method(StringIO, "open", strio_s_open, -1);
rb_define_method(StringIO, "initialize", strio_initialize, -1);
rb_define_method(StringIO, "initialize_copy", strio_copy, 1);