Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Pathname#each_child

(?::boolish with_directory) { (::Pathname) -> void } -> ::Array[::Pathname]
(?::boolish with_directory) -> ::Enumerator[::Pathname, ::Array[::Pathname]]
each_child(with_dirnames = true) {|entry| ... } → array_of_pathnames
each_child(with_dirnames = true) → new_enumerator

With a block given and with_dirnames given as true (the default), yields a new pathname for each child of the entry represented by self; returns an array of those pathnames:

Example
Pathname('include').each_child {|child| p child }
# #<Pathname:include/ruby>
# #<Pathname:include/ruby.h>
# => [#<Pathname:include/ruby>, #<Pathname:include/ruby.h>]

With a block given and with_dirnames given as false, yields a new pathname for each child of the entry represented by self with its dirname omitted; returns an array of those pathnames:

Example
Pathname('include').each_child(false) {|child| p child }
# #<Pathname:ruby>
# #<Pathname:ruby.h>
# => [#<Pathname:ruby>, #<Pathname:ruby.h>]

Note that entries '.' and '..' are not children.

With no block given, returns a new Enumerator.

See also #dirname #each_entry #directory? #each_filename also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0