Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
Dir.[]
(*::path patterns, ?base: ::path?, ?sort: bool) -> ::Array[::String]
Dir[*patterns, base: nil, sort: true] → array
dir.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/dir.rb, line 223
def self.[](*args, base: nil, sort: true)
Primitive.dir_s_aref(args, base, sort)
end
Like Dir.glob, but does not accept keyword argument flags, and may take multiple patterns as arguments:
Example
Dir['*.rb', '*.h'].take(3) # => ["KNOWNBUGS.rb", "array.rb", "ast.rb"]
Ruby version changes
-
3.0
-
Dir.globandDir.[]now sort the results by default, and accept thesort:keyword option. [Feature #8709]
-