Forum: Ruby analyzer.rb cannot run.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Genocide L. (Guest)
on 2009-02-03 13:07
Attachment: text.txt (0 Bytes)
Hi, I'm kinda new to this programmin thing and I'm currently using
windows vista and it seems whenever I run this file:

line = File.readlines("text.txt")
lines_count = lines.size
text = lines.join
puts "#{line_count} lines"

It will show :

>ruby C:/Users/administrator/analyzer.rb
*** WARNING *** Windows users should check the "Run process in terminal"
check box in the Debugger Preferences
to see STDOUT and STDERR output in real time.

C:/Users/administrator/analyzer.rb:2: undefined local variable or method
`lines' for main:Object (NameError)
>exit

and as you can see, there's an error in the code but I can't seem to
find out what. I have attached the text maybe someone can run it and
tell me what's wrong?

Thanks,

Gen
Brian C. (Guest)
on 2009-02-03 13:16
Genocide L. wrote:
> Hi, I'm kinda new to this programmin thing and I'm currently using
> windows vista and it seems whenever I run this file:
>
> line = File.readlines("text.txt")
> lines_count = lines.size
> text = lines.join
> puts "#{line_count} lines"
>
> It will show :
>
>>ruby C:/Users/administrator/analyzer.rb
> *** WARNING *** Windows users should check the "Run process in terminal"
> check box in the Debugger Preferences
> to see STDOUT and STDERR output in real time.
>
> C:/Users/administrator/analyzer.rb:2: undefined local variable or method
> `lines' for main:Object (NameError)
>>exit
>
> and as you can see, there's an error in the code but I can't seem to
> find out what. I have attached the text maybe someone can run it and
> tell me what's wrong?

The error message does tell you exactly the problem: it's on line 2 of
analyzer.rb, and the problem is that you referred to something called
"lines" but no such thing exists. That is, there is no local variable or
method called "lines"

On line 1 you created a local variable called "line", not "lines" :-)

HTH,

Brian.
Genocide L. (Guest)
on 2009-02-03 16:47
Ha ha, okay, I realized now. I copied the codes wrong too. Anyhow, I got
it done awhile ago. Thankx yeah! :-)

P.S. what does HTH means.... -.-
Todd B. (Guest)
on 2009-02-03 17:18
(Received via mailing list)
On Tue, Feb 3, 2009 at 8:46 AM, Genocide L. 
<removed_email_address@domain.invalid> wrote:
> Ha ha, okay, I realized now. I copied the codes wrong too. Anyhow, I got
> it done awhile ago. Thankx yeah! :-)
>
> P.S. what does HTH means.... -.-

In this group, it usually means "hope that helps", or "hope that
helped".

You can google internet acronyms to see some others in use.  There's
also a wiktionary page dedicated to such a thing:

http://en.wiktionary.org/wiki/Appendix:Internet_slang

Todd
This topic is locked and can not be replied to.