Require Error

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 /Users/josephinechang/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:inrequire’
from b.rb:1:in `’”

I’m not sure what the problem is. Thanks in advance to anyone who can
help me.

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.

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

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 /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:inrequire’
from b.rb:1:in `’

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 methodrequire_relevant’ for main:Object