I am working on a project where I have a dynamically determined mount point and am provided a set of absolute paths to do work on on the target volume. Since these files don't exist yet, I am using the Pathname class to handle the filename manipulations. However, Pathname seems to be doing something a bit clever when it comes to concatenating paths that have the same root. I have observed the following behavior:
p1 = Pathname.new('/foo/bar') # #<Pathname:/foo/bar>
p2 = Pathname.new('/baz/quux') # #<Pathname:/baz/quux>
p3 = p1 + p2 # #<Pathname:/baz/quux>
p4 = p1.join p2.relative_path_from(Pathname.new('/')) # #<Pathname:/foo/bar/baz/quux>
p5 = Pathname.new(p1.to_s.concat p2) # #<Pathname:/foo/bar/baz/quux>
So with p4 and p5, I am able to get the behavior I wanted, but the constructions are a little contrived. Is there a cleaner way to do this?