Ruby

[Ruby] 絶対パス間の相対パスを作る

More than 5 years have passed since last update.

自作する前に捜せば、大抵あるよということで。

path_from = Pathname('/a/b/c')

path_to = Pathname('/a/b/c/d/e')
path_to.relative_path_from(path_from).to_s
#=> "d/e"
path_to = Pathname('/a/x/y')
path_to.relative_path_from(path_from).to_s
#=> "../../x/y"

使えるのはRuby 1.8.1から。