End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Dir#each_child
dir.each_child {| filename | block } → dir
dir.each_child → an_enumerator
dir.c
View on GitHub ↗
static VALUE
dir_each_child_m(VALUE dir)
{
RETURN_ENUMERATOR(dir, 0, 0);
return dir_each_entry(dir, dir_yield, Qnil, TRUE);
}
Calls the block once for each entry except for “.” and “..” in this directory, passing the filename of each entry as a parameter to the block.
If no block is given, an enumerator is returned instead.
Example
d = Dir.new("testdir") d.each_child {|x| puts "Got #{x}" }
produces:
Example
Got config.h Got main.rb