def +(other)
other = Pathname.new(other) unless Pathname === other
return other if other.absolute?
path1 = @path
path2 = other.to_s
while m2 = %r{\A\.\.(?:/+|\z)}.match(path2) and
m1 = %r{(\A|/+)([^/]+)\z}.match(path1) and
%r{\A(?:\.|\.\.)\z} !~ m1[2]
path1 = m1[1].empty? ? '.' : '/' if (path1 = m1.pre_match).empty?
path2 = '.' if (path2 = m2.post_match).empty?
end
if %r{\A/+\z} =~ path1
while m2 = %r{\A\.\.(?:/+|\z)}.match(path2)
path2 = '.' if (path2 = m2.post_match).empty?
end
end
return Pathname.new(path2) if path1 == '.'
return Pathname.new(path1) if path2 == '.'
if %r{/\z} =~ path1
Pathname.new(path1 + path2)
else
Pathname.new(path1 + '/' + path2)
end
end