7stud2
(7stud --)
13 June 2013 20:35
1
I am trying to load a ruby program into irb and it will not load.
i have tried typing:
load ' personal_chef.rb'
load 'personal_chef.rb '
As well as using the entire path name and I always get the same message:
LoadError: cannot load such file
from<irb>:1:in 'load'
from<irb>:1
I have ruby version 2.00 and its on windows 7.
Any ideas? I feel like this is a simple problem like spacing or
something, but I just can't figure it out...
···
--
Posted via http://www.ruby-forum.com/ .
stomar
(stomar)
13 June 2013 20:54
2
why do you put whitespace in the path?
try
load 'personal_chef.rb'
···
Am 13.06.2013 22:35, schrieb Eric D.:
I am trying to load a ruby program into irb and it will not load.
i have tried typing:
load ' personal_chef.rb'
load 'personal_chef.rb '
--
<https://github.com/stomar/> ;
7stud2
(7stud --)
13 June 2013 21:09
3
Tried it exactly as you wrote it and the same error message arose.
I put the white space in because one of the other forums said that some
of the text editors(sublime, textmate etc. add white spaces)
···
--
Posted via http://www.ruby-forum.com/ .
7stud2
(7stud --)
13 June 2013 22:27
4
Try Dir.pwd to see where irb is looking for the file. You might need the
full path.
···
--
Posted via http://www.ruby-forum.com/ .
7stud2
(7stud --)
13 June 2013 22:29
5
I did that it says C:/Users/Eric.
Is there anyway I can change the directory to some other location?
···
--
Posted via http://www.ruby-forum.com/ .
stomar
(stomar)
14 June 2013 05:27
6
Make sure you start irb from the directory where the file is located.
You can list the files in that directory with
Dir['*']
If you see your file on this list, load 'file.rb' should work.
Otherwise you need to specify the full path.
···
Am 13.06.2013 22:35, schrieb Eric D.:
I am trying to load a ruby program into irb and it will not load.
--
<https://github.com/stomar/> ;
7stud2
(7stud --)
14 June 2013 06:40
7
Dir.chdir should change the path to whatever you specify. If you want to
change the starting path you'll need to launch irb with the command
prompt when you're in your chosen folder, or add a command to your
.irbrc file.
···
--
Posted via http://www.ruby-forum.com/ .
7stud2
(7stud --)
18 June 2013 21:27
8
The directory change worked! Thank you both for your help. One question
though, when I try to load a text file from a program in ruby it says
undefined method `each' for "text.txt":String (NoMethodError).
My code looks like this:
File.open ("text.txt").each {|line| puts line}
Both the text.txt and the program loading it are in the same directory.
Any suggestions?
···
--
Posted via http://www.ruby-forum.com/ .
7stud2
(7stud --)
18 June 2013 21:33
9
Never mind i figured it out. Thank you guys! Great forum!
···
--
Posted via http://www.ruby-forum.com/ .
7stud2
(7stud --)
19 June 2013 06:40
10
I'd use
File.foreach( 'text.txt' ) {|line| puts line }
···
--
Posted via http://www.ruby-forum.com/ .
7stud2
(7stud --)
19 June 2013 16:20
11
Apologies. On the loading issue that I eluded to early it was the
spacing mentioned in unknown (Guest)'s post.
···
--
Posted via http://www.ruby-forum.com/ .
stomar
(stomar)
19 June 2013 05:37
12
File.open("text.txt").each {|line| puts line }
Never put a space between method name and '('.
BTW. When you figure it out by yourself, you should also include
the solution in your "Never mind" post. In case other people
have a similar problem.
···
Am 18.06.2013 23:27, schrieb Eric D.:
though, when I try to load a text file from a program in ruby it says
undefined method `each' for "text.txt":String (NoMethodError).
My code looks like this:
File.open ("text.txt").each {|line| puts line}
--
<https://github.com/stomar/> ;