harungo
harungo

Reputation: 219

Ruby require error

I'm trying to call the file from the file cpu.rb from main.rb:

require 'rubygems'
require 'cpu.rb'

But it does not work. I use Netbeans and Ruby 1.9.2. What's the problem?

Upvotes: 1

Views: 1255

Answers (1)

Dylan Markow
Dylan Markow

Reputation: 124449

Ruby 1.9.2 does not include the current file's directory in $LOAD_PATH.

You can try using require_relative instead:

require_relative 'cpu.rb'

Or you can supply the actual path:

require './cpu.rb'

Or you can add the current file's directory to the load path:

$LOAD_PATH.unshift File.dirname(__FILE__)
require 'cpu.rb'

Upvotes: 4

Related Questions