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

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

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

Example
Pathname('/path/to/some/file.rb').ascend {|dirname| p dirname}
#<Pathname:/path/to/some/file.rb>
#<Pathname:/path/to/some>
#<Pathname:/path/to>
#<Pathname:/path>
#<Pathname:/>

With no block given, returns a new Enumerator.