Simple Newbie IO question

I’m pretty new to Ruby but I’m willing to bet that there are some things that
IRB won’t handle well. IO streams may be one of them.

Can anyone else expand on this one?

Christopher J. Meisenzahl CPS, CSTE
Senior Software Testing Consultant
Spherion
christopher.j.meisenzahl@citicorp.com

···

-----Original Message-----
From: montana [mailto:montana@buc99.bsd.st]
Sent: Friday, November 15, 2002 2:21 PM
To: ruby-talk
Cc: montana
Subject: 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:in open’
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’m pretty new to Ruby but I’m willing to bet that there are some things that
IRB won’t handle well. IO streams may be one of them.

Can anyone else expand on this one?

The problem was not with irb, as Bruce pointed out. But on the matter, I’ll
put my hand on my heart and say that irb has never failed me!

Gavin

···

From: christopher.j.meisenzahl@citicorp.com