Skip to content

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

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

  1. 3.0
See also .chdir .children also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0