无法在Ruby脚本中加载相对文件

时间:2019-07-20 12:02:11

标签: ruby ruby-2.6

文件组织如下:

- myScriptProject
  - solutions.ru
  - main.ru

solution.ru

def test_function
  puts 'Hello World'
end

main.rb

#!/Users/myusername/.rbenv/shims/ruby

require './solution' # or require_relative 'solution'

test_function

我正在尝试运行脚本:

$ cd myScriptProject/
$ ruby main.ru

然后我收到一条LoadError消息。

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

1 个答案:

答案 0 :(得分:1)

Ruby的脚本扩展名是at checkExecSyncError (child_process.js:616:11) at execFileSync (child_process.js:634:15) at runOnAllDevices (/home/dipanshuchaubey/Documents/practice/native/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:75:39) at buildAndRun (/home/dipanshuchaubey/Documents/practice/native/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:137:41) at /home/dipanshuchaubey/Documents/practice/native/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:103:12 at processTicksAndRejections (internal/process/task_queues.js:89:5) at async Command.handleAction (/home/dipanshuchaubey/Documents/practice/native/node_modules/react-native/node_modules/@react-native-community/cli/build/cliEntry.js:160:7) 而不是rb