each()
public
Calls the block once for each entry 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.
d = Dir.new("testdir")
d.each {|x| puts "Got #{x}" }
produces:
Got .
Got ..
Got config.h
Got main.rb
Show source
static VALUE
dir_each(VALUE dir)
{
struct dir_data *dirp;
struct dirent *dp;
IF_HAVE_READDIR_R(DEFINE_STRUCT_DIRENT entry);
RETURN_ENUMERATOR(dir, 0, 0);
GetDIR(dir, dirp);
rewinddir(dirp->dir);
while (READDIR(dirp->dir, dirp->enc, &STRUCT_DIRENT(entry), dp)) {
rb_yield(rb_external_str_new_with_enc(dp->d_name, NAMLEN(dp), dirp->enc));
if (dirp->dir == NULL) dir_closed();
}
return dir;
}