Skip to content

Commit 914c726

Browse files
committed
Make Pathname#each_entry return enumerator if called without block
Fixes [Bug #18158]
1 parent c97ac00 commit 914c726

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

ext/pathname/pathname.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,7 @@ static VALUE
12741274
path_each_entry(VALUE self)
12751275
{
12761276
VALUE args[1];
1277+
RETURN_ENUMERATOR(self, 0, 0);
12771278

12781279
args[0] = get_strpath(self);
12791280
return rb_block_call(rb_cDir, id_foreach, 1, args, each_entry_i, rb_obj_class(self));

test/pathname/test_pathname.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,18 @@ def test_each_entry
13551355
}
13561356
end
13571357

1358+
def test_each_entry_enumerator
1359+
with_tmpchdir('rubytest-pathname') {|dir|
1360+
open("a", "w") {}
1361+
open("b", "w") {}
1362+
a = []
1363+
e = Pathname(".").each_entry
1364+
assert_kind_of(Enumerator, e)
1365+
e.each {|v| a << v }
1366+
assert_equal([Pathname("."), Pathname(".."), Pathname("a"), Pathname("b")], a.sort)
1367+
}
1368+
end
1369+
13581370
def test_mkdir
13591371
with_tmpchdir('rubytest-pathname') {|dir|
13601372
Pathname("d").mkdir

0 commit comments

Comments
 (0)