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

ruby-changes:65305

From: nagachika <ko1@a...>
Date: Sat, 20 Feb 2021 18:47:10 +0900 (JST)
Subject: [ruby-changes:65305] 0cfd491732 (ruby_2_7): merge revision(s) 9241211538189a58b477bd55b539357617fd42ed: [Backport #17589]

https://git.ruby-lang.org/ruby.git/commit/?id=0cfd491732

From 0cfd491732162eab61227ac4b49617c37ddbb316 Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@r...>
Date: Sat, 20 Feb 2021 18:06:43 +0900
Subject: merge revision(s) 9241211538189a58b477bd55b539357617fd42ed: [Backport
 #17589]

	Forward keyword arguments for Pathname#each_line [Bug #17589]

	---
	 ext/pathname/pathname.c        |  4 ++--
	 test/pathname/test_pathname.rb | 26 ++++++++++++++++++++++++++
	 2 files changed, 28 insertions(+), 2 deletions(-)
---
 ext/pathname/pathname.c        |  4 ++--
 test/pathname/test_pathname.rb | 26 ++++++++++++++++++++++++++
 version.h                      |  2 +-
 3 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c
index 15f80d4..0f48545 100644
--- a/ext/pathname/pathname.c
+++ b/ext/pathname/pathname.c
@@ -360,10 +360,10 @@ path_each_line(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L360
     args[0] = get_strpath(self);
     n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
     if (rb_block_given_p()) {
-        return rb_block_call(rb_cFile, id_foreach, 1+n, args, 0, 0);
+        return rb_block_call_kw(rb_cFile, id_foreach, 1+n, args, 0, 0, RB_PASS_CALLED_KEYWORDS);
     }
     else {
-        return rb_funcallv(rb_cFile, id_foreach, 1+n, args);
+        return rb_funcallv_kw(rb_cFile, id_foreach, 1+n, args, RB_PASS_CALLED_KEYWORDS);
     }
 }
 
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb
index 2ce32a6..e5168d5 100644
--- a/test/pathname/test_pathname.rb
+++ b/test/pathname/test_pathname.rb
@@ -690,6 +690,32 @@ class TestPathname < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/pathname/test_pathname.rb#L690
     }
   end
 
+  def test_each_line_opts
+    with_tmpchdir('rubytest-pathname') {|dir|
+      open("a", "w") {|f| f.puts 1, 2 }
+      a = []
+      Pathname("a").each_line(chomp: true) {|line| a << line }
+      assert_equal(["1", "2"], a)
+
+      a = []
+      Pathname("a").each_line("2", chomp: true) {|line| a << line }
+      assert_equal(["1\n", "\n"], a)
+
+      a = []
+      Pathname("a").each_line(1, chomp: true) {|line| a << line }
+      assert_equal(["1", "", "2", ""], a)
+
+      a = []
+      Pathname("a").each_line("2", 1, chomp: true) {|line| a << line }
+      assert_equal(["1", "\n", "", "\n"], a)
+
+      a = []
+      enum = Pathname("a").each_line(chomp: true)
+      enum.each {|line| a << line }
+      assert_equal(["1", "2"], a)
+    }
+  end
+
   def test_readlines
     with_tmpchdir('rubytest-pathname') {|dir|
       open("a", "w") {|f| f.puts 1, 2 }
diff --git a/version.h b/version.h
index 04c8aa2..b0d01d9 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L2
 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
 #define RUBY_VERSION_TEENY 3
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 158
+#define RUBY_PATCHLEVEL 159
 
 #define RUBY_RELEASE_YEAR 2021
 #define RUBY_RELEASE_MONTH 2
-- 
cgit v1.1


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

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