Forum: Ruby 'require' is not loading files

385f556af0dc83a3f6194c4c7319c5d8?d=identicon&s=25 Elliot M. (elliot_m)
on 2013-06-03 06:25
I am new to ruby and have been teaching it to myself for the past so I
am still very new to Ruby. I have been trying to load external
source-code files into my program but for some reason every time I try
use require to load a file it does not work and I get this message

LoadError: cannot load such file -- b
        from
/usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
`require'
        from
/usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in
`require'
        from (irb):3
        from /usr/local/bin/irb:12:in `<main>'
irb(main):004:0> require


For example I create a file named a.rb and then in another program I try
to load it with require 'a' but I always get this message. When I use
load 'a.rb' it loads the file with no problem but I can not figure out
why require '' will not load the files into the program. Like I said I
am very new to Ruby so any help is appreciated.
3853dd5371ac1e094fc45d6c2aa0e459?d=identicon&s=25 Carlo E. Prelz (Guest)
on 2013-06-03 07:33
(Received via mailing list)
Subject: 'require' is not loading files
  Date: lun 03 giu 13 01:25:10 +0900
Sorry for the delay!

Quoting Elliot M. (lists@ruby-forum.com):

> I am new to ruby and have been teaching it to myself for the past so I
> am still very new to Ruby. I have been trying to load external
> source-code files into my program but for some reason every time I try
> use require to load a file it does not work and I get this message
>
> LoadError: cannot load such file -- b

Recent Ruby does not include the current directory when looking for
scripts to load. Either use

require './b'

or, maybe more expressive, use

require_relative 'b'

You can also opt to include '.' in the RUBYLIB global variable.

Carlo
8f854b1bbfb03aa2a7855b532abdac18?d=identicon&s=25 windwiny (Guest)
on 2013-06-03 07:46
(Received via mailing list)
require './b'

or

require_relative 'b'


2013/6/3 Elliot M. <lists@ruby-forum.com>
15000f55138ae94b0f362ed7c625461a?d=identicon&s=25 unknown (Guest)
on 2013-06-03 14:19
(Received via mailing list)
Am 03.06.2013 07:32, schrieb Carlo E. Prelz:
> require './b'
>
> or, maybe more expressive, use
>
> require_relative 'b'

Note that require_relative will not work with irb.
385f556af0dc83a3f6194c4c7319c5d8?d=identicon&s=25 Elliot M. (elliot_m)
on 2013-06-03 21:10
Thank you for the help. require './a' works just like it should.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.