Module: Pathname::Extensions::Partial
- Defined in:
- lib/pathname/extensions/partial.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#partial(n) ⇒ Object
Extract a partial path from the path.
Class Method Details
.included(host) ⇒ Object
8 9 10 11 |
# File 'lib/pathname/extensions/partial.rb', line 8 def self.included(host) host.load_extensions :explode super end |
Instance Method Details
#partial(n) ⇒ Object
Extract a partial path from the path. Include +n+ directories from the front end (left hand side) if +n+ is positive. Include |+n+| directories from the back end (right hand side) if +n+ is negative.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pathname/extensions/partial.rb', line 16 def partial(n) dirs = dirname.explode partial_dirs = if n.positive? dirs[0...n] elsif n.negative? dirs.reverse[0...-n].reverse else HERE end Pathname(File.join(partial_dirs)) end |