End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Pathname#each_child
each_child(with_directory=true, &b)
ext/pathname/lib/pathname.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/ext/pathname/lib/pathname.rb, line 493
def each_child(with_directory=true, &b)
children(with_directory).each(&b)
end
Iterates over the children of the directory (files and subdirectories, not recursive).
It yields Pathname object for each child.
By default, the yielded pathnames will have enough information to access the files.
If you set with_directory to false, then the returned pathnames will contain the filename only.
Example
Pathname("/usr/local").each_child {|f| p f } #=> #<Pathname:/usr/local/share> # #<Pathname:/usr/local/bin> # #<Pathname:/usr/local/games> # #<Pathname:/usr/local/lib> # #<Pathname:/usr/local/include> # #<Pathname:/usr/local/sbin> # #<Pathname:/usr/local/src> # #<Pathname:/usr/local/man> Pathname("/usr/local").each_child(false) {|f| p f } #=> #<Pathname:share> # #<Pathname:bin> # #<Pathname:games> # #<Pathname:lib> # #<Pathname:include> # #<Pathname:sbin> # #<Pathname:src> # #<Pathname:man>
Note that the results never contain the entries . and .. in the directory because they are not children.