Project

General

Profile

Actions

Feature #13969

closed

Dir#each_child

Added by znz (Kazuhiro NISHIYAMA) about 7 years ago. Updated almost 7 years ago.

Status:
Closed
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 2 (0 open2 closed)

Related to Ruby master - Feature #11302: Dir.entries and Dir.foreach without [".", ".."]Closedmatz (Yukihiro Matsumoto)Actions
Related to Ruby master - Feature #12010: Exclude dot and dotdot from Dir#eachClosedmatz (Yukihiro Matsumoto)Actions
Actions #1

Updated by znz (Kazuhiro NISHIYAMA) about 7 years ago

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

Updated by nobu (Nobuyoshi Nakada) about 7 years 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);
Actions #4

Updated by nobu (Nobuyoshi Nakada) almost 7 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r62022.


dir.c: Dir#each_child

  • dir.c (dir_each_child_m): new instance methods Dir#each_child
    and Dir#children. [Feature #13969]
Actions #5

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Related to Feature #12010: Exclude dot and dotdot from Dir#each added
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0