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

ruby-changes:60111

From: Nobuyoshi <ko1@a...>
Date: Tue, 18 Feb 2020 14:38:29 +0900 (JST)
Subject: [ruby-changes:60111] 041c2932e3 (master): Pass keyword arguments to IOs properly [Bug #16639]

https://git.ruby-lang.org/ruby.git/commit/?id=041c2932e3

From 041c2932e336b509b0ddc1fdbd9f160bce8d4893 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 18 Feb 2020 14:34:26 +0900
Subject: Pass keyword arguments to IOs properly [Bug #16639]


diff --git a/io.c b/io.c
index 201ec9b..19fe51b 100644
--- a/io.c
+++ b/io.c
@@ -12430,10 +12430,14 @@ argf_block_call_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, argf)) https://github.com/ruby/ruby/blob/trunk/io.c#L12430
     return Qnil;
 }
 
+#define ARGF_block_call(mid, argc, argv, func, argf) \
+    rb_block_call_kw(ARGF.current_file, mid, argc, argv, \
+                     func, argf, rb_keyword_given_p())
+
 static void
 argf_block_call(ID mid, int argc, VALUE *argv, VALUE argf)
 {
-    VALUE ret = rb_block_call(ARGF.current_file, mid, argc, argv, argf_block_call_i, argf);
+    VALUE ret = ARGF_block_call(mid, argc, argv, argf_block_call_i, argf);
     if (ret != Qundef) ARGF.next_p = 1;
 }
 
@@ -12449,7 +12453,7 @@ argf_block_call_line_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, argf)) https://github.com/ruby/ruby/blob/trunk/io.c#L12453
 static void
 argf_block_call_line(ID mid, int argc, VALUE *argv, VALUE argf)
 {
-    VALUE ret = rb_block_call(ARGF.current_file, mid, argc, argv, argf_block_call_line_i, argf);
+    VALUE ret = ARGF_block_call(mid, argc, argv, argf_block_call_line_i, argf);
     if (ret != Qundef) ARGF.next_p = 1;
 }
 
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index a76bdcc..277fa36 100644
--- a/test/ruby/test_argf.rb
+++ b/test/ruby/test_argf.rb
@@ -725,6 +725,13 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L725
                       ["\"a\\n\\n\"", "\"b\\n\""], [])
   end
 
+  def test_each_line_chomp
+    assert_in_out_err(['-e', 'ARGF.each_line(chomp: false) {|para| p para}'], "a\nb\n",
+                      ["\"a\\n\"", "\"b\\n\""], [])
+    assert_in_out_err(['-e', 'ARGF.each_line(chomp: true) {|para| p para}'], "a\nb\n",
+                      ["\"a\"", "\"b\""], [])
+  end
+
   def test_each_byte
     ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
       {#
-- 
cgit v0.10.2


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

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