1

这很难用谷歌搜索。我有一个文件位于

/folder_1/folder_2/folder_3/my_ruby_file_to_be_executed.rb 

在那个文件里面我需要这个文件

/folder_1/folder_4/file_to_require.rb

我无法锻炼如何编写从一个到另一个的相对路径。
我正在使用红宝石 1.93

4

1 回答 1

5

在您的路径中使用..将备份您的文件夹。因此,如果您要从folder_3back 移动到folder_2然后再返回到folder_1,您将需要这样的东西:

# my_ruby_file_to_be_executed.rb 
require_relative '../../folder_4/file_to_require.rb'
于 2013-09-27T19:20:03.290 回答