文件组织如下:
- myScriptProject
- solutions.ru
- main.ru
solution.ru
def test_function
puts 'Hello World'
end
主.rb
#!/Users/myusername/.rbenv/shims/ruby
require './solution' # or require_relative 'solution'
test_function
我正在尝试运行脚本:
$ cd myScriptProject/
$ ruby main.ru
然后我收到了一条加载错误消息。
Traceback (most recent call last):
2: from test.ru:3:in `<main>'
1: from /Users/myusername/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/myusername/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- ./solution (LoadError)
在这种情况下可能有什么问题?
顺便说一下,我的Ruby环境是由rbenv管理的。
$ which ruby
$ /Users/myusername/.rbenv/shims/ruby
Ruby的脚本扩展rb
不是ru
。