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

ruby-changes:70776

From: Jeremy <ko1@a...>
Date: Fri, 7 Jan 2022 09:42:22 +0900 (JST)
Subject: [ruby-changes:70776] dd6a75195a (master): [ruby/pathname] Make Pathname#each_entry return enumerator if called without block

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

From dd6a75195a635abfcfdb8ac5df26885e91708908 Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Fri, 17 Sep 2021 12:12:08 -0700
Subject: [ruby/pathname] Make Pathname#each_entry return enumerator if called
 without block

Fixes [Bug #18158]

https://github.com/ruby/pathname/commit/914c726aa2
---
 ext/pathname/pathname.c        |  1 +
 test/pathname/test_pathname.rb | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c
index 1d4ed2814bb..00ca85205bb 100644
--- a/ext/pathname/pathname.c
+++ b/ext/pathname/pathname.c
@@ -1274,6 +1274,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L1274
 path_each_entry(VALUE self)
 {
     VALUE args[1];
+    RETURN_ENUMERATOR(self, 0, 0);
 
     args[0] = get_strpath(self);
     return rb_block_call(rb_cDir, id_foreach, 1, args, each_entry_i, rb_obj_class(self));
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb
index 9e14668c99f..c971597602b 100644
--- a/test/pathname/test_pathname.rb
+++ b/test/pathname/test_pathname.rb
@@ -1355,6 +1355,18 @@ class TestPathname < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/pathname/test_pathname.rb#L1355
     }
   end
 
+  def test_each_entry_enumerator
+    with_tmpchdir('rubytest-pathname') {|dir|
+      open("a", "w") {}
+      open("b", "w") {}
+      a = []
+      e = Pathname(".").each_entry
+      assert_kind_of(Enumerator, e)
+      e.each {|v| a << v }
+      assert_equal([Pathname("."), Pathname(".."), Pathname("a"), Pathname("b")], a.sort)
+    }
+  end
+
   def test_mkdir
     with_tmpchdir('rubytest-pathname') {|dir|
       Pathname("d").mkdir
-- 
cgit v1.2.1


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

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