Uninitialised Constant Files <NameError>

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

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

Thank you in advance
Deepika

Try Files without ‘s’.

if Sub==“DATE” :array_sentence=File.readlines(“date.txt”)

Deepika Yp wrote:

in program I was thrown with the error:

Uninitialised Constant Files

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”.

Michal Zacik wrote:

Try Files without ‘s’.

if Sub==“DATE” :array_sentence=File.readlines(“date.txt”)

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

Thanks a lot !!! it worked…

On Mon, Aug 24, 2009 at 4:43 AM, 7stud –[email protected] wrote:

Michal Zacik wrote:

Try Files without ‘s’.

if Sub==“DATE” :array_sentence=File.readlines(“date.txt”)

…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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs