[前][次][番号順一覧][スレッド一覧]

ruby-changes:48309

From: nobu <ko1@a...>
Date: Wed, 25 Oct 2017 21:04:59 +0900 (JST)
Subject: [ruby-changes:48309] nobu:r60423 (trunk): io.c: warn old write

nobu	2017-10-25 21:04:53 +0900 (Wed, 25 Oct 2017)

  New Revision: 60423

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60423

  Log:
    io.c: warn old write
    
    * io.c (rb_io_puts): warn if write method accepts just one
      argument.  [ruby-core:83529] [Feature #14042]

  Modified files:
    trunk/io.c
    trunk/test/ruby/test_io.rb
Index: test/ruby/test_io.rb
===================================================================
--- test/ruby/test_io.rb	(revision 60422)
+++ test/ruby/test_io.rb	(revision 60423)
@@ -2458,6 +2458,22 @@ End https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2458
     end)
   end
 
+  def test_puts_old_write
+    capture = String.new
+    def capture.write(str)
+      self << str
+    end
+
+    capture.clear
+    assert_warning(/[.#]write is outdated/) do
+      stdout, $stdout = $stdout, capture
+      puts "hey"
+    ensure
+      $stdout = stdout
+    end
+    assert_equal("hey\n", capture)
+  end
+
   def test_display
     pipe(proc do |w|
       "foo".display(w)
Index: io.c
===================================================================
--- io.c	(revision 60422)
+++ io.c	(revision 60423)
@@ -1690,6 +1690,13 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/io.c#L1690
 rb_io_writev(VALUE io, int argc, VALUE *argv)
 {
     if (argc > 1 && rb_obj_method_arity(io, id_write) == 1) {
+	if (io != rb_stderr && RTEST(ruby_verbose)) {
+	    VALUE klass = CLASS_OF(io);
+	    char sep = FL_TEST(klass, FL_SINGLETON) ? (klass = io, '.') : '#';
+	    rb_warning("%+"PRIsVALUE"%c""write is outdated interface"
+		       " which accepts just one argument",
+		       klass, sep);
+	}
 	do rb_io_write(io, *argv++); while (--argc);
 	return argv[0];		/* unused right now */
     }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]