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
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 837
def ascend
return to_enum(__method__) unless block_given?
path = @path
yield self
while r = chop_basename(path)
path, = r
break if path.empty?
yield self.class.new(del_trailing_separator(path))
end
end
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.
See also
#add_trailing_separator
#atime
#absolute?
#basename
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0