Simple Newbie IO question

Hi Everyone-

I’m reading the “Pick-axe” book. In the chapter on IO it discusses File.open.

Straight from the book:
File.open(“testfile”, “r”) do |aFile|

… process the file

end

I tried something similar in irb:
irb(main):001:0> File.open(“testfile”, “w”) do |aFIle|
irb(main):002:1* aFile << "Hello,\nWorld!"
irb(main):003:1> end
NameError: undefined local variable or method aFile' for #<Object:0x153cd8> from (irb):2 from (irb):1:inopen’
from (irb):1

What am I doing wrong here??

What is the correct way to pass a string to a file and then open that file again to read it?

Thanks.
SA

I tried something similar in irb:
irb(main):001:0> File.open(“testfile”, “w”) do |aFIle|
irb(main):002:1* aFile << “Hello,\nWorld!”
irb(main):003:1> end
NameError: undefined local variable or method aFile' for #<Object:0x153cd8> from (irb):2 from (irb):1:in open’
from (irb):1

What am I doing wrong here??

You misspelled |aFile|

What is the correct way to pass a string to a file and then open that file
again to read it?

If you mean write a string to a file, close and reopen to read it, it could be
done:

File::open(‘afile’, ‘w’){ |file| file << aString }

sometime later…

var = File::open(‘afile’){ |file| file.read }

···

On Friday 15 November 2002 02:20 pm, montana wrote:

Bruce R. Williams