summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS6
-rw-r--r--dir.c9
-rw-r--r--test/ruby/test_dir.rb3
3 files changed, 18 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 0f5f448f0b..9174577811 100644
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,12 @@ with all sufficient information, see the ChangeLog file or Redmine
=== Core classes updates (outstanding ones only)
+* Dir
+
+ * New methods:
+
+ * added Dir#each_child and Dir#children instance methods. [Feature #13969]
+
* Proc
* Proc#call doesn't change $SAFE any more. [Feature #14250]
diff --git a/dir.c b/dir.c
index 26cc122d5b..71eb93516f 100644
--- a/dir.c
+++ b/dir.c
@@ -2860,6 +2860,13 @@ dir_s_each_child(int argc, VALUE *argv, VALUE io)
}
static VALUE
+dir_each_child_m(VALUE dir)
+{
+ RETURN_ENUMERATOR(dir, 0, 0);
+ return dir_each_entry(dir, dir_yield, Qnil, TRUE);
+}
+
+static VALUE
dir_collect_children(VALUE dir)
{
VALUE ary = rb_ary_new();
@@ -3212,6 +3219,8 @@ Init_Dir(void)
rb_define_method(rb_cDir,"inspect", dir_inspect, 0);
rb_define_method(rb_cDir,"read", dir_read, 0);
rb_define_method(rb_cDir,"each", dir_each, 0);
+ rb_define_method(rb_cDir,"each_child", dir_each_child_m, 0);
+ rb_define_method(rb_cDir,"children", dir_collect_children, 0);
rb_define_method(rb_cDir,"rewind", dir_rewind, 0);
rb_define_method(rb_cDir,"tell", dir_tell, 0);
rb_define_method(rb_cDir,"seek", dir_seek, 1);
diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb
index cead4beb93..9a1a51ef51 100644
--- a/test/ruby/test_dir.rb
+++ b/test/ruby/test_dir.rb
@@ -232,14 +232,17 @@ class TestDir < Test::Unit::TestCase
end
def test_foreach
+ assert_entries(Dir.open(@root) {|dir| dir.each.to_a})
assert_entries(Dir.foreach(@root).to_a)
end
def test_children
+ assert_entries(Dir.open(@root) {|dir| dir.children}, true)
assert_entries(Dir.children(@root), true)
end
def test_each_child
+ assert_entries(Dir.open(@root) {|dir| dir.each_child.to_a}, true)
assert_entries(Dir.each_child(@root).to_a, true)
end