Forum: Ruby Uncaught exception: cannot load such file --

Posted by Prog Rammer (proggrammer)
on 2012-12-17 12:09
There is an empty file called include_test.rb and a file test.rb which
includes include_test.rb
i.e. the content of test.rb:
require 'include_test.rb'

if I run:
ruby test.rb it gives following error:

Uncaught exception: cannot load such file -- include_test
Posted by Carlo E. Prelz (Guest)
on 2012-12-17 12:19
(Received via mailing list)
Subject: Uncaught exception: cannot load such file --
  Date: Mon 17 Dec 12 08:10:01PM +0900

Quoting Prog Rammer (lists@ruby-forum.com):

> if I run:
> ruby test.rb it gives following error:
>
> Uncaught exception: cannot load such file -- include_test

Try

require './include_test.rb'

or

require_relative 'include_test.rb'

Carlo
Posted by Prog Rammer (proggrammer)
on 2012-12-17 13:07
Carlo E. Prelz wrote in post #1089363:
> Subject: Uncaught exception: cannot load such file --
>   Date: Mon 17 Dec 12 08:10:01PM +0900
>
> Quoting Prog Rammer (lists@ruby-forum.com):
>
>> if I run:
>> ruby test.rb it gives following error:
>>
>> Uncaught exception: cannot load such file -- include_test
>
> Try
>
> require './include_test.rb'
is working.
> or
>
> require_relative 'include_test.rb'
gives error: LoadError: cannot infer basepath

> Carlo
Is it so that require 'file_name' doesnt work with ruby 1.9.3 but works 
for 1.8.7?
Posted by Prog Rammer (proggrammer)
on 2012-12-17 13:27
Prog Rammer wrote in post #1089367:
> Carlo E. Prelz wrote in post #1089363:
>> Subject: Uncaught exception: cannot load such file --
>>   Date: Mon 17 Dec 12 08:10:01PM +0900
>>
>> Quoting Prog Rammer (lists@ruby-forum.com):
>>

>>> Uncaught exception: cannot load such file -- include_test
>>
>> Try
>>
>> require './include_test.rb'
> is working.
>> or
>>
>> require_relative 'include_test.rb'
> gives error: LoadError: cannot infer basepath
>
>> Carlo
> Is it so that require 'file_name' doesnt work with ruby 1.9.3 but works
> for 1.8.7?
I dont think that is the case as it is working fine on ubuntu, but not
on windows.
Posted by Carlo E. Prelz (Guest)
on 2012-12-17 14:28
(Received via mailing list)
Subject: Re: Uncaught exception: cannot load such file --
  Date: Mon 17 Dec 12 09:07:26PM +0900

Quoting Prog Rammer (lists@ruby-forum.com):

> Is it so that require 'file_name' doesnt work with ruby 1.9.3 but works
> for 1.8.7?

Ruby looks for include files that do not explicitly specify a path in
a series of paths. Some are hardcoded. To them you can add other paths
by including them in global variable "RUBYLIB".

From what I remember, ruby 1.8 included the current directory in the
hardcoded paths. This is not true anymore with 1.9. But if you specify
(in Linux)

export RUBYLIB='.'

then you will not need to specify the './' before your include file.

Carlo
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.