End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
Dir.each_child
Dir.each_child( dirname ) {| filename | block } → nil
Dir.each_child( dirname, encoding: enc ) {| filename | block } → nil
Dir.each_child( dirname ) → an_enumerator
Dir.each_child( dirname, encoding: enc ) → an_enumerator
dir.c
View on GitHub ↗
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;
}
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.
Example
Dir.each_child("testdir") {|x| puts "Got #{x}" }
produces:
Example
Got config.h Got main.rb