Skip to content

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

class method

Dir.open

open(name, encoding: nil) { |dir| ... }
Dir.open( string ) -> aDir
Dir.open( string, encoding: enc ) -> aDir
Dir.open( string ) {| aDir | block } -> anObject
Dir.open( string, encoding: enc ) {| aDir | block } -> anObject

The optional encoding keyword argument specifies the encoding of the directory. If not specified, the filesystem encoding is used.

With no block, open is a synonym for Dir::new. If a block is present, it is passed aDir as a parameter. The directory is closed at the end of the block, and Dir::open returns the value of the block.

See also .new .pwd .mktmpdir .rmdir also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1