Forum: Ruby Require Error

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
42c86b1256b1c7fa498b7bf72041d4fd?d=identicon&s=25 Anthony Chang (royk)
on 2014-06-27 18:44
I'm trying to do a very simple require method with two files.

1. "a.rb"
puts "Hello, from a.rb."

2. "b.rb"
require 'a'
puts "Hello from b.rb"
require 'a'
puts "Hello again from b.rb"

Both are located in the same directory.

When I run b.rb, however, I get the following error:

`require': cannot load such file -- a.rb (LoadError)
  from b.rb:1:in `<main>'"

I'm not sure what the problem is. Thanks in advance to anyone who can
help me.
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-06-27 20:32
Use require_relative for a require with relative paths. Otherwise you'll
need to provide the full path, or add that directory to your PATH.
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2014-06-28 03:45
For your own messing around, you can also do:

   require './a'

The problem with that is it assumes you are running the program from the
directory that contains a.rb--if that is not be the case, then
require won't be able to find the file...hence the need for
04b91d89078088d8bedce729d38aa606?d=identicon&s=25 Alan Seigerman (seigs)
on 2014-07-02 01:38
I am having the identical problem as Anthony Chang.  Files a.rb and b.rb
are in the same directory, but "require" is coming back with the same
error message Anthony described.

`require': cannot load such file -- a (LoadError)
  from b.rb:1:in `<main>'

The error first occurred after I upgrading my OS which included Ruby

I tried replacing require with require_relevant and received the
following error msg

b.rb:1:in `<main>': undefined method `require_relevant' for main:Object

This topic is locked and can not be replied to.