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#descend

() { (::Pathname) -> untyped } -> nil
() -> ::Enumerator[::Pathname, nil]
descend {|entry| ... } → nil
descend → new_enumerator

With a block given, yields a new pathname for each successive dirname in the stored path; see File.dirname:

Example
# Absolute path.
Pathname('/path/to/some/file.rb').descend {|pn| p pn }
# #<Pathname:/>
# #<Pathname:/path>
# #<Pathname:/path/to>
# #<Pathname:/path/to/some>
# #<Pathname:/path/to/some/file.rb>
# Relative path.
Pathname('path/to/some/file.rb').descend {|pn| p pn }
# #<Pathname:path>
# #<Pathname:path/to>
# #<Pathname:path/to/some>
# #<Pathname:path/to/some/file.rb>

With no block given, returns a new Enumerator.

See also #delete #directory? #ctime #dirname also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0