Ruby 1.9.2 require issue

J

Justin Whalley

Hi, I'm new to Ruby. I am trying to use require to bring in methods.rb,
which is located on my hard drive in the Chapter05 folder. Getting the
following error:

C:\Users\Whalley\Training\Ruby\Practice\Chapter05>ruby methods.rb

C:\Users\Whalley\Training\Ruby\Practice\Chapter05>irb
irb(main):001:0> require "methods.rb"
LoadError: no such file to load -- methods.rb
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from (irb):1
from C:/Ruby192/bin/irb:12:in `<main>'
irb(main):002:0>


Anyone know what I can do to resolve this? I am following along with a
video tutorial that is using 1.8.?, and they are getting it returned as
"true" without any Load Errors.

Any and all help will be much appreciated.

Thanks.
 
L

Luis Lavena

Hi, I'm new to Ruby. I am trying to use require to bring in methods.rb,
which is located on my hard drive in the Chapter05 folder. Getting the
following error:

C:\Users\Whalley\Training\Ruby\Practice\Chapter05>ruby methods.rb

C:\Users\Whalley\Training\Ruby\Practice\Chapter05>irb
irb(main):001:0> require "methods.rb"
LoadError: no such file to load -- methods.rb
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from (irb):1
        from C:/Ruby192/bin/irb:12:in `<main>'
irb(main):002:0>

Anyone know what I can do to resolve this? I am following along with a
video tutorial that is using 1.8.?, and they are getting it returned as
"true" without any Load Errors.

Any and all help will be much appreciated.

http://www.ruby-lang.org/en/news/2010/08/18/ruby-1-9.2-released/

FAQ Section:

"It causes a LoadError
$: doesn't include the current directory. Some script may need
modifications to work properly."

The current directory is no longer included in the $LOAD_PATH ($:)

You need to include it to have the compatibility behavior of 1.8.x

irb -I.

or ruby -I. script.rb
 
Q

Quintus

Am 19.12.2010 19:17, schrieb Justin Whalley:
Hi, I'm new to Ruby. I am trying to use require to bring in methods.rb,
which is located on my hard drive in the Chapter05 folder. Getting the
following error:

C:\Users\Whalley\Training\Ruby\Practice\Chapter05>ruby methods.rb

C:\Users\Whalley\Training\Ruby\Practice\Chapter05>irb
irb(main):001:0> require "methods.rb"
LoadError: no such file to load -- methods.rb
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from (irb):1
from C:/Ruby192/bin/irb:12:in `<main>'
irb(main):002:0>


Anyone know what I can do to resolve this? I am following along with a
video tutorial that is using 1.8.?, and they are getting it returned as
"true" without any Load Errors.

Any and all help will be much appreciated.

Thanks.

From the official ruby-lang.org website
(http://www.ruby-lang.org/en/news/2010/08/18/ruby-1-9.2-released/):

==============================================
It causes a LoadError
$: doesn't include the current directory. Some script may need
modifications to work properly.
==============================================

I.e., "." is not one of the directories Ruby searches for scripts to
require. Either use require_relative (which doesn't work in IRB, because
there is no source file one could require relative to) or use

require "./yourscript.rb"

But PLEASE do not use that inside normal scripts, that's what
require_relative is made for (and require_relative does some more than
the code I gave above).

Vale,
Marvin
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top