Project

General

Profile

Feature #13969

Dir#each_child

Added by znz (Kazuhiro NISHIYAMA) 2 months ago. Updated about 2 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:83102]

Description

Dir has class method pairs: Dir.entries / Dir.children, Dir.foreach / Dir.each_child.
But instance method is Dir#each only.
How about adding Dir#each_child?


Related issues

Related to Ruby trunk - Feature #11302: Dir.entries and Dir.foreach without [".", ".."]Closed

History

#1 Updated by znz (Kazuhiro NISHIYAMA) 2 months ago

  • Related to Feature #11302: Dir.entries and Dir.foreach without [".", ".."] added

#2 [ruby-core:83376] Updated by nobu (Nobuyoshi Nakada) about 2 months ago

diff --git a/dir.c b/dir.c
index 44d309195c..242afa131d 100644
--- a/dir.c
+++ b/dir.c
@@ -2743,6 +2743,13 @@ dir_s_each_child(int argc, VALUE *argv, VALUE io)
     return Qnil;
 }

+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)
 {
@@ -3104,6 +3111,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);

Also available in: Atom PDF