Skip to content

Commit

Permalink
Make Pathname#each_entry return enumerator if called without block
Browse files Browse the repository at this point in the history
Fixes [Bug #18158]
  • Loading branch information
jeremyevans committed Jan 7, 2022
1 parent c97ac00 commit 914c726
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions ext/pathname/pathname.c
Expand Up @@ -1274,6 +1274,7 @@ static VALUE
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));
Expand Down
12 changes: 12 additions & 0 deletions test/pathname/test_pathname.rb
Expand Up @@ -1355,6 +1355,18 @@ def test_each_entry
}
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
Expand Down

0 comments on commit 914c726

Please sign in to comment.