Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
Dir.glob
(::array[::path] | ::path pattern, ?::int flags, ?base: ::path?, ?sort: bool) -> ::Array[::String]
(::array[::path] | ::path pattern, ?::int flags, ?base: ::path?, ?sort: bool) { (::String pathname) -> void } -> nil
Dir.glob(patterns, flags: 0, base: '.', sort: true) → array_of_entries
Dir.glob(patterns, flags: 0, base: '.', sort: true) {|entry_name| ... } → nil
dir.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/dir.rb, line 239
def self.glob(pattern, _flags = 0, flags: _flags, base: nil, sort: true)
Primitive.attr! :use_block
Primitive.dir_s_glob(pattern, flags, base, sort)
end
Returns an array of filesystem entries; see Filename Globbing.
With a block given, calls the block with each of the selected entry names and returns nil:
Example
Dir.glob('*.rb') {|entry_name| puts entry_name } # => nil
Ruby version changes
-
4.1
-
Dir.globsupports***/for recursive matching that follows directory symbolic links, stopping at links to ancestor directories. [Feature #17548]
-
-
3.0
-
Dir.globandDir.[]now sort the results by default, and accept thesort:keyword option. [Feature #8709]
-