End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
Dir.open
Dir.open( string ) → aDir
Dir.open( string, encoding: enc ) → aDir
Dir.open( string ) {| aDir | block } → anObject
Dir.open( string, encoding: enc ) {| aDir | block } → anObject
dir.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/dir.rb, line 97
def self.open(name, encoding: nil, &block)
dir = Primitive.dir_s_open(name, encoding)
if block
begin
yield dir
ensure
Primitive.dir_s_close(dir)
end
else
dir
end
end
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.