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:
parent
6baa78bb78
commit
dd6a75195a
2 changed files with 13 additions and 0 deletions
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue