Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Dir#each

dir.each { |filename| block } → dir
dir.each → an_enumerator

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.

Example
d = Dir.new("testdir")
d.each  {|x| puts "Got #{x}" }

produces:

Got .
Got ..
Got config.h
Got main.rb
See also #close #each_child #children #fileno also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1