Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Dir#scan
scan → entries
scan {|entry_name, entry_type| ... } → nil
dir.c
View on GitHub ↗
static VALUE
dir_scan_children(VALUE dir)
{
if (rb_block_given_p()) {
dir_each_entry(dir, dir_yield_with_type, Qnil, TRUE);
return Qnil;
}
else {
VALUE ary = rb_ary_new();
dir_each_entry(dir, dir_yield_with_type, ary, TRUE);
return ary;
}
}
Scans the entries in self, except for '.' and '..'.
With no block given, returns entries, an array of 2-element arrays. Each nested array contains an entry name and its type:
Example
dir = Dir.new('/example') dir.scan # => [["config.h", :file], ["lib", :directory], ["main.rb", :file]]
With a block given, calls the block with each entry name and its type; returns nil:
Example
entries = [] dir.scan do |entry_name, entry_type| entries << [entry_name, entry_type] end # => nil entries # => [["config.h", :file], ["lib", :directory], ["main.rb", :file]]