0

I have two files:

  1. A Ruby file that contains both a class definition and a sample script. This is simply called 'foo' since I would like to run it as an executable in certain circumstances.

  2. A Ruby test script named 'bar.rb' that tests the tests that methods of 'foo.'

When trying to include 'foo' in 'bar.rb' I encounter a require error:

gem_original_require': no such file to load -- foo (LoadError)

However, if I rename 'foo' to 'foo.rb' the problem disappears! From my understanding, the Ruby 'require' method should be able to load data even from non '*.rb' files.

Is there a way to import the functionality of 'foo' without changing the file suffix? Does anyone have an explanation for the behavior exhibited?

Michael Hang
  • 199
  • 2
  • 2
  • 15

1 Answers1

1

A file that require loads has to have an extension that is explicitly stated in the argument of require, or otherwise, be either .rb or .so.

Solution for you is to use load instead.

sawa
  • 165,429
  • 45
  • 277
  • 381