Class: Pathname
- Inherits:
-
Object
- Object
- Pathname
- Defined in:
- lib/sixarm_ruby_pathname_dirnames.rb
Instance Method Summary (collapse)
-
- (Object) dirnames
Return an enumerable of pathnames created by calling #dirname repeatedly.
Instance Method Details
- (Object) dirnames
Return an enumerable of pathnames created by calling #dirname repeatedly. This can be useful for traversing directories upwards to parent, grandparent, etc.
Example:
p = Pathname.new('/foo/goo/hoo.txt')
p.dirnames
#=> ['/foo/goo', '/foo', '/']
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sixarm_ruby_pathname_dirnames.rb', line 19 def dirnames path = self # start at the current path results = [] while true dirname = path.dirname break if dirname == path results << dirname path = dirname end return results end |