instance method
Pathname#each_child
(?::boolish with_directory) { (::Pathname) -> void } -> ::Array[::Pathname]
(?::boolish with_directory) -> ::Enumerator[::Pathname, ::Array[::Pathname]]
each_child(with_directory=true, &b)
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/pathname_builtin.rb, line 808
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.