Require problem

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.

On Fri, Nov 5, 2010 at 4:26 PM, Roni K. [email protected]
wrote:

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

On Fri, Nov 5, 2010 at 9:15 PM, Roni K. [email protected]
wrote:

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 G.

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.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs