Skip to content
instance method

Pathname#descend

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

Iterates over and yields a new Pathname object for each element in the given path in descending order.

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

Pathname.new('path/to/some/file.rb').descend {|v| p v}
   #<Pathname:path>
   #<Pathname:path/to>
   #<Pathname:path/to/some>
   #<Pathname:path/to/some/file.rb>

Returns an Enumerator if no block was given.

enum = Pathname.new("/usr/bin/ruby").descend
  # ... do stuff ...
enum.each { |e| ... }
  # yields Pathnames /, /usr, /usr/bin, and /usr/bin/ruby.

It doesn’t access the filesystem.

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