require problem

R

Roni Kekkonen

Hello. I am working with the book "Everyday scripting with Ruby" (The
Pragmatic Programmers) and I'm at chapter 7 where I have touse require
to load up a file I have made myself (churn.rb). But everytime I run my
program, it complains the following:

(internal:lib/rubygems/custom_require):29:in 'recuire': no such file to
load -- churn (LoadError)
from (internal:lib/rubygems/custom_require):29:in 'require
from churntests.rb:2:in '(main)'

now, both files 'churn.rb' and 'churntests.rb' are in the same folder
(I'm programming under Windows) so churn should work. I even tried to
see if the textbook's files would work and even with them I got the same
error message.

I just can't understand it... I mean, I have the following lines at the
beginning of my churntests.rb:

require 'test/unit'
require 'churn'

and I have a ruby file named exactly as "churn.rb" in the same folder
where my churntests.rb is located at, so everything should be in order,
but somehow the require doesn't work...

I would appreciate it if someone could help me with my problem.
 
A

Ammar Ali

Hello. I am working with the book "Everyday scripting with Ruby" (The
Pragmatic Programmers) and I'm at chapter 7 where I have touse require
to load up a file I have made myself (churn.rb). But everytime I run my
program, it complains the following:

(internal:lib/rubygems/custom_require):29:in 'recuire': no such file to
load -- churn (LoadError)
=C2=A0 =C2=A0 =C2=A0from (internal:lib/rubygems/custom_require):29:in 're= quire
=C2=A0 =C2=A0 =C2=A0from churntests.rb:2:in '(main)'

now, both files 'churn.rb' and 'churntests.rb' are in the same folder
(I'm programming under Windows) so churn should work. I even tried to
see if the textbook's files would work and even with them I got the same
error message.

I just can't understand it... I mean, I have the following lines at the
beginning of my churntests.rb:

require 'test/unit'
require 'churn'

Ruby 1.9 no longer includes the current directory in the load path.
Add a './' before the file name, like so:

require './churn'

There are other options as well, like require_relative, and adding the
current directory to the load path. I leave them up to you to
investigate.

It's remarkable how much confusion this change has caused. Especially
for people with older books who insist that they typed the code
*exactly* as it in the book. It is a change for the better though.

What's up with the 'recuire' (c instead of q) in the error message?
Did you edit it?

Regards,
Ammar
 
R

Roni Kekkonen

Ruby 1.9 no longer includes the current directory in the load path.
Add a './' before the file name, like so:

require './churn'

There are other options as well, like require_relative, and adding the
current directory to the load path. I leave them up to you to
investigate.

Thank you very much, Ammar. That explains a lot. I trust you when you
say that it is indeed a change for the better, even if I can't see it
right now how it might improve things.

What's up with the 'recuire' (c instead of q) in the error message?
Did you edit it?

Yeah, it was my bad. I could not copy/paste the error message from the
command prompt, so I tried to write it as accurately as I could, but
seems as though Ive missed something after all. Well, all's well now.

Roni
 
P

Phillip Gawlowski

Thank you very much, Ammar. That explains a lot. I trust you when you
say that it is indeed a change for the better, even if I can't see it
right now how it might improve things.

Consider <http://www.microsoft.com/technet/security/advisory/2269637.mspx>.

--
Phillip Gawlowski

Though the folk I have met,
(Ah, how soon!) they forget
When I've moved on to some other place,
There may be one or two,
When I've played and passed through,
Who'll remember my song or my face.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top