-2

Files are organized as follows:

- 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

I was trying to run the scripts:

$ cd myScriptProject/
$ ruby main.ru

Then I got an LoadError message.

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)

What could be the issue in this case?

By the way, my Ruby environment is managed by rbenv.

$ which ruby
$ /Users/myusername/.rbenv/shims/ruby
Hiro Shaw
  • 385
  • 3
  • 18

1 Answers1

1

Ruby's script extension is rb not ru.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103