我正在使用Practicing Ruby's Self-Guided Course on Stream, File Formats, and Sockets,並在pre-built test for the first exercise中遇到以下問題。下面的測試腳本應該在目錄更改爲data
子目錄中的項目文件夾:`__FILE__`不能在`DATA` /`__END__`中工作
eval(DATA.read) # load the test helper script
... # various calls to test method defined below
__END__
dir = File.dirname(__FILE__)
Dir.chdir("#{dir}/data")
...
但是,這打破了,因爲__FILE__
回報(eval)
(而不是文件路徑)和File.dirname(__FILE__)
回報.
這是怎麼回事,而如何編寫它來產生預期的輸出呢?
希望我的問題是,現在更清晰 –