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.
0dd8411e267c1d64f683df70df48e1f5?d=identicon&s=25 Anthony C. (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.
9627ec27e4fb3a18be02133b4ddaa901?d=identicon&s=25 Joel P. (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.
5989a003d261c0abe6d08570ff6cc3d0?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
146e9d6d37de5129d865b255fdcd6969?d=identicon&s=25 Alan S. (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.