1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/pathname] Make Pathname#each_entry return enumerator if called without block

Fixes [Bug #18158]

https://github.com/ruby/pathname/commit/914c726aa2
This commit is contained in:
Jeremy Evans 2021-09-17 12:12:08 -07:00 committed by git
parent 6baa78bb78
commit dd6a75195a
2 changed files with 13 additions and 0 deletions

View file

@ -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));

View file

@ -1355,6 +1355,18 @@ class TestPathname < Test::Unit::TestCase
}
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