Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Pathname#children
(?::boolish with_directory) -> ::Array[::Pathname]
children(with_dirnames = true) → array_of_pathnames
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 1018
def children(with_directory=true)
with_directory = false if @path == '.'
result = Dir.children(@path)
if with_directory
result.map! {|e| self.class.new(File.join(@path, e))}
else
result.map! {|e| self.class.new(e)}
end
result
end
Returns an array of pathnames; each represents a child of the entry represented by self, which must be an existing directory in the underlying file system.
With with_dirnames given as true (the default), each pathname contains the full entry:
Example
Pathname('lib').children.size # => 72 Pathname('lib').children.take(3) # => [#<Pathname:lib/bundled_gems.rb>, #<Pathname:lib/bundler>, #<Pathname:lib/bundler.rb>]
With with_dirnames given as false, each pathname contains only the basename of the entry:
Example
Pathname('lib').children(false).take(3) # => [#<Pathname:bundled_gems.rb>, #<Pathname:bundler>, #<Pathname:bundler.rb>]
Note that entries . and .. in directory are not actually children, and so are never included in the result.