I am working on a project where I have a dynamically defined mount point, and I have provided a set of absolute paths to work on the target volume. Since these files do not yet exist, I use the Pathname class to handle file name manipulations. However, Pathname seems to do something a little smart when it comes to concatenating paths that have the same root. I 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 can get the behavior I wanted, but the constructs are a bit far-fetched. Is there a cleaner way to do this?
source share