Question

I've been trying to get a ruby file to require another ruby file and I feel like I'm going crazy. My setup is as follows

Two files in '/raid1/ruby-code/benchmark/'

CommandRunner
Benchmarker

Benchmarker is the main program at this point and wants to require CommandRunner, I've tried a bunch of different things and none of them work. The following is a list of all of the things I've put at the beginning of Benchmarker

require 'CommandRunner'
require './CommandRunner'
$LOAD_PATH.unshift File.expand_path(File.dirname($PROGRAM_NAME))
require 'CommandRunner'
$LOAD_PATH.unshift File.expand_path(File.dirname($PROGRAM_NAME))
require './CommandRunner'

I've also tried all of the above permutations using require_relative. I've tried it loading the file into irb inside of emacs, and I've tried it at the command line. At one point in irb it would load once with

require 'CommandRunner'
and then would load until I switched it back to './CommandRunner' and then it would load once again.

I've actually had the error say

`require_relative': no such file to load -- 
/raid1/ruby-code/benchmark/CommandRunner (LoadError)

which is the correct path to the file!

I've since switched it to load and that seems to be working, I'm seeing weird behavior but that just might be me. Does anyone have any idea what would be going on here?

Was it helpful?

Solution

Is the name of the file CommandRunner and not CommandRunner.rb? The standard naming convention for ruby files is to use lowercase and underscores, so even though the class name would be CommandRunner, the file would be command_runner.rb, and then require 'command_runner' should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top