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#read

dir.read → string or nil

Reads the next entry from dir and returns it as a string. Returns nil at the end of the stream.

Example
d = Dir.new("testdir")
d.read   #=> "."
d.read   #=> ".."
d.read   #=> "config.h"
See also #pos= #rewind #pos #seek also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1