class method
Dir.new
(::path dir, ?encoding: ::encoding?) -> ::Dir
Dir.new(dirpath) → dir
Dir.new(dirpath, encoding: nil) → dir
dir.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/dir.rb, line 211
def initialize(name, encoding: nil)
Primitive.dir_initialize(name, encoding)
end
Returns a new Dir object for the directory at dirpath:
Example
Dir.new('.') # => #<Dir:.>
The value given with optional keyword argument encoding specifies the encoding for the directory entry names; if nil (the default), the file system’s encoding is used:
Example
Dir.new('.').read.encoding # => #<Encoding:UTF-8> Dir.new('.', encoding: Encoding::US_ASCI).read.encoding # => #<Encoding:US-ASCII>