我目前正在尝试创建一个程序来解决Mars Rover kata。
我无法在IRB中加载文件。每次我尝试加载任何文件时都会说:
LoadError: cannot load such file -- ./plateau
from /Users/Emma01/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/Emma01/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/Emma01/projects/marsrover/lib/rover.rb:1:in `<top (required)>'
from /Users/Emma01/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/Emma01/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from (irb):1
from /Users/Emma01/.rvm/rubies/ruby-2.1.1/bin/irb:11:in `<main>'
我的文件结构是rover
,plateau
和compass
,我尝试了各种方法来要求程序中的文件。 Rover规范示例如下:
require 'plateau'
require 'rover'
答案 0 :(得分:0)
由于require
不知道相对路径,请在脚本中使用此提示require
:
=> Dir['*.rb'] #<- show .rb scripts in this dir
=> ["foo.rb"]
=> require 'foo.rb'
#> LoadError: cannot load such file -- foo.rb #<- try load file
=> $: << '.' #<- add current dir to load path
=> require 'foo' #<- require you .rb script
=> true
或者像@DylanMarkow那样使用require_relative
。