def relative_path_from(base_directory)
if self.absolute? != base_directory.absolute?
raise ArgumentError,
"relative path between absolute and relative path: #{self.inspect}, #{base_directory.inspect}"
end
dest = []
self.cleanpath.each_filename {|f|
next if f == '.'
dest << f
}
base = []
base_directory.cleanpath.each_filename {|f|
next if f == '.'
base << f
}
while !base.empty? && !dest.empty? && base[0] == dest[0]
base.shift
dest.shift
end
if base.include? '..'
raise ArgumentError, "base_directory has ..: #{base_directory.inspect}"
end
base.fill '..'
relpath = base + dest
if relpath.empty?
Pathname.new(".")
else
Pathname.new(relpath.join('/'))
end
end