IRB不允许我加载我的文件?

时间:2014-07-16 17:22:09

标签: ruby irb

我目前正在尝试创建一个程序来解决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>'

我的文件结构是roverplateaucompass,我尝试了各种方法来要求程序中的文件。 Rover规范示例如下:

require 'plateau'

require 'rover'

1 个答案:

答案 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