Uninitialised Constant Files <NameError>

D

Deepika Yp

Hi all,

I was trying a simple Ruby program using flat files ,but at certain
point in a program which says:
if Sub=="DATE" :array_sentence=Files.readlines("date.txt")

in program I was thrown with the error:

Uninitialised Constant Files <NameError>

It would be great if somebody could guide me with this error.

Thank you in advance
Deepika
 
M

Michal Zacik

Try Files without 's'.

if Sub=="DATE" :array_sentence=File.readlines("date.txt")
 
B

Brian Candler

Deepika said:
in program I was thrown with the error:

Uninitialised Constant Files <NameError>

It would be great if somebody could guide me with this error.

Identifiers which start with a capital letter are constants.

The error says that there is no constant in your program called "Files".
Unless you have defined one, this is correct.

However there is a constant (class) in the standard library called
"File".
 
R

Rick DeNatale

...but then you're left with trying to assign to a symbol.

Yep, I suspect he (kind of) wants

if sub=="DATE" : array_sentence=File.readlines("date.txt") end

Now I don't think that this form of if is particularly attractive, and
Ruby 1.9 has done away with using : for then.

I'd rewrite this using the if modifier:

array_sentence=File.readlines("date.txt") if sub=="DATE"


--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
 

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