Method: Dir.each_child

Defined in:
dir.c

.each_child(dirname) {|filename| ... } ⇒ nil .each_child(dirname, encoding: enc) {|filename| ... } ⇒ nil .each_child(dirname) ⇒ Object .each_child(dirname, encoding: enc) ⇒ Object

Calls the block once for each entry except for “.” and “..” in the named directory, passing the filename of each entry as a parameter to the block.

If no block is given, an enumerator is returned instead.

Dir.each_child("testdir") {|x| puts "Got #{x}" }

produces:

Got config.h
Got main.rb

Overloads:

  • .each_child(dirname) {|filename| ... } ⇒ nil

    Yields:

    • (filename)

    Returns:

    • (nil)
  • .each_child(dirname, encoding: enc) {|filename| ... } ⇒ nil

    Yields:

    • (filename)

    Returns:

    • (nil)

3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
# File 'dir.c', line 3021

static VALUE
dir_s_each_child(int argc, VALUE *argv, VALUE io)
{
    VALUE dir;

    RETURN_ENUMERATOR(io, argc, argv);
    dir = dir_open_dir(argc, argv);
    rb_ensure(dir_each_child, dir, dir_close, dir);
    return Qnil;
}