module Pathname::Extensions::Partial

Public Class Methods

included(host) click to toggle source
Calls superclass method
# File lib/pathname/extensions/partial.rb, line 8
def self.included(host)
  host.load_extensions :explode
  super
end

Public Instance Methods

partial(n) click to toggle source

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.

# 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