假设我知道我开始的绝对路径以及我想要达到的绝对路径:
first = '/first/path'
second = '/second/path'
Run Code Online (Sandbox Code Playgroud)
现在我想弄清楚如何构造一个相对于第一个的路径.例如:
# answer should be /first/path/../../second/path
path = second.get_path_relative_to(first)
Run Code Online (Sandbox Code Playgroud)
我怎么能在Ruby中做这种事情?