# Basic beginner help needed

**URL:** <https://www.ruby-forum.com/t/basic-beginner-help-needed/192152>\
**Category:** Ruby\
**Created:** [July 25, 2010, 4:28am UTC](https://www.ruby-forum.com/t/basic-beginner-help-needed/192152 "2010-07-25T04:28:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![karlhoover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4da419/32.png) [@karlhoover](https://www.ruby-forum.com/u/karlhoover)\
**Post date:** [July 25, 2010, 4:28am UTC](https://www.ruby-forum.com/t/basic-beginner-help-needed/192152/1 "2010-07-25T04:28:11Z")

</div>

I am new to Ruby and have been looking for some basic beginner help. I  
have not been able to find a beginner forum anywhere, so I apologize if  
this is too basic a question for this group. I have installed ruby  
1.9.1 on my windows 7 pc and have had success using interactive ruby  
(and the Windows command prompt). Where I am stuck is creating a script  
in notepad and then running that script. It seems a bit peculiar to me  
that all the beginning tutorials that I have tried just say to create  
these scripts, but they donâ€™t mention where they need to be saved. I  
also have not come across any tutorials that cover configuring the ruby  
file path. I believe I have written and named the scripts properly, but  
when I try to open them, I get the error message:

NameError: undefined local variable or method â€˜helloâ€™ for main:Object  
from (irb):1  
from C:/Ruby191/bin/irb:12:in â€˜â€™

Any help would be much appreciated.

---

<div class="post-metadata">

**Author:** ![karlhoover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4da419/32.png) [@karlhoover](https://www.ruby-forum.com/u/karlhoover)\
**Post date:** [July 25, 2010, 5:13am UTC](https://www.ruby-forum.com/t/basic-beginner-help-needed/192152/2 "2010-07-25T05:13:24Z")

</div>

please provide your script first…then we can do a little help

On Sun, Jul 25, 2010 at 10:28 AM, Karl Halvorson

---

<div class="post-metadata">

**Author:** ![karlhoover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4da419/32.png) [@karlhoover](https://www.ruby-forum.com/u/karlhoover)\
**Post date:** [July 25, 2010, 6:02am UTC](https://www.ruby-forum.com/t/basic-beginner-help-needed/192152/3 "2010-07-25T06:02:00Z")

</div>

Hello Karl,

Try going through these books to get started in Ruby -  
[http://www.humblelittlerubybook.com/book/hlrb.pdf](http://www.humblelittlerubybook.com/book/hlrb.pdf)  
[http://www.sapphiresteel.com/The-Book-Of-Ruby](http://www.sapphiresteel.com/The-Book-Of-Ruby)

I have quoted these as they are readily available on the internet for  
free. And as pointed out by Heruacles, posting the code snippet with  
which you have a problem will help the forum give you better answers.

After you write code in notepad (try notepad++ or any other code editor  
which will give you syntax highlighting, this will help you learn  
easily) save the file with a .rb extension anywhere on your computer  
(have a separate folder for this to keep your ruby files in one place).

Setting the PATH environment variable to the ruby-\>bin folder helps you  
launch the ruby interpreter from the command line (from any path). If  
you have installed ruby in your C drive for e.g., the bin dir would be  
c:\ruby-1.9.1\bin  
Add this path to the PATH environment variable.

After this, you can open command prompt, navigate to the path where you  
saved your ruby file and type ‘ruby filename’. For e.g, if you have  
saved your file in a folder called ‘my scripts’ on D with the name  
‘first.rb’, you must type the following in the command prompt  
D:\my scripts\>ruby first.rb

Karl Halvorson wrote:

> I am new to Ruby and have been looking for some basic beginner help. I  
> have not been able to find a beginner forum anywhere, so I apologize if  
> this is too basic a question for this group. I have installed ruby  
> 1.9.1 on my windows 7 pc and have had success using interactive ruby  
> (and the Windows command prompt). Where I am stuck is creating a script  
> in notepad and then running that script. It seems a bit peculiar to me  
> that all the beginning tutorials that I ahave tried just say to create  
> these scripts, but they donâ€™t mention where they need to be saved. I  
> also have not come across any tutorials that cover configuring the ruby  
> file path. I believe I have written and named the scripts properly, but  
> when I try to open them, I get the error message:
> 
> NameError: undefined local variable or method â€˜helloâ€™ for main:Object  
> from (irb):1  
> from C:/Ruby191/bin/irb:12:in â€˜â€™
> 
> Any help would be much appreciated.

---

<div class="post-metadata">

**Author:** ![karlhoover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4da419/32.png) [@karlhoover](https://www.ruby-forum.com/u/karlhoover)\
**Post date:** [July 25, 2010, 10:36pm UTC](https://www.ruby-forum.com/t/basic-beginner-help-needed/192152/4 "2010-07-25T22:36:56Z")

</div>

On Sun, Jul 25, 2010 at 3:28 AM, Karl Halvorson  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> when I try to open them, I get the error message:
> 
> NameError: undefined local variable or method â€˜helloâ€™ for main:Object  
> from (irb):1  
> from C:/Ruby191/bin/irb:12:in â€˜â€™

My apologies if the following is too elementary.

I don’t know how other users run Ruby programs from Microsoft Windows,  
but I  
mostly use batch files.  
Or, to be precise, one batch file which takes various parameters to run  
different Ruby programs using different versions of Ruby. (There are  
some  
online utilities to help you do that, but I’ve temporarily forgotten  
what  
they are called!)

A simple version is the following. Suppose you save your ruby program as  
progname.rb in  
C:\ruby\_programs\_directory  
or whatever you want to call the directory. (It doesn’t have to be a  
directory in the root.)  
You can set up a Microsoft Windows batch file with the following command  
call “C:\ruby19\bin\ruby.exe” -v “C:\ruby\_programs\_directory%1.rb”  
suppose we call that batch file rr.bat  
Then you can run the ruby program progname.rb by going into  
a Command Prompt window and typing.  
rr %1

Does that help any?

(As X Heruacles said, if you post the script you have written, and also  
the  
commands you are using to try to run it, then we may eb able to give you  
a  
correction. From the error message, you are trying to run the script in  
IRB?)

---

<div class="post-metadata">

**Author:** ![karlhoover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4da419/32.png) [@karlhoover](https://www.ruby-forum.com/u/karlhoover)\
**Post date:** [July 26, 2010, 6:17pm UTC](https://www.ruby-forum.com/t/basic-beginner-help-needed/192152/5 "2010-07-26T18:17:02Z")

</div>

> entered the text

Looks that way here, too. Good work!

> 

Sure thing. I ran your code and saw the same output. So you’re doing  
everything right, this is something with scite. I have no real idea  
what’s  
happening to make the process hang, but a little research shows that  
it’s  
related to the call to gets, and further research shows that this is a  
known  
problem with scite.

There’s a solution, though! Running the script from the command prompt  
will  
work fine.

StartMenu → All Programs → Ruby191 → “Start Command Prompt with Ruby”  
cd “C:\Documents and Settings\Karl Halvorson\My Documents\Ruby\My  
Ruby Tutorial scripts”

Now run the script using ruby! Type:  
ruby “name of script”

> 

[How To Manage Environment Variables in Windows XP - Microsoft Support](http://support.microsoft.com/kb/310519) discusses environment variables,  
including the PATH. With the ruby windows installer, you get the  
shortcut  
that we used above to start a command prompt with the right environment  
for  
using ruby. However, if you want you set up your environment so that  
it’s  
always correct for running ruby from the command line, so that you can  
use a  
regular command prompt to run ruby programs instead of needing to use  
the  
specific shortcut that the installer gave you.

---

<div class="post-metadata">

**Author:** ![karlhoover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4da419/32.png) [@karlhoover](https://www.ruby-forum.com/u/karlhoover)\
**Post date:** [July 27, 2010, 1:29am UTC](https://www.ruby-forum.com/t/basic-beginner-help-needed/192152/6 "2010-07-27T01:29:31Z")

</div>

Thanks James!

The scripts are working from ‘Start Comand Promp with Ruby’ as you  
instructed. I think the problem with the command prompt before was not  
first switching to the directory where the .rb files are located. I  
think it is odd that the three or more tutorials that I have looked at  
do not mention this.

Thanks again for all your help.

James wrote:

> > entered the text
> 
> Looks that way here, too. Good work!
> 
> > 
> 
> Sure thing. I ran your code and saw the same output. So you’re doing  
> everything right, this is something with scite. I have no real idea  
> what’s  
> happening to make the process hang, but a little research shows that  
> it’s  
> related to the call to gets, and further research shows that this is a  
> known  
> problem with scite.
> 
> There’s a solution, though! Running the script from the command prompt  
> will  
> work fine.
> 
> StartMenu → All Programs → Ruby191 → “Start Command Prompt with Ruby”  
> cd “C:\Documents and Settings\Karl Halvorson\My Documents\Ruby\My  
> Ruby Tutorial scripts”
> 
> Now run the script using ruby! Type:  
> ruby “name of script”
> 
> > 
> 
> [How To Manage Environment Variables in Windows XP - Microsoft Support](http://support.microsoft.com/kb/310519) discusses environment variables,  
> including the PATH. With the ruby windows installer, you get the  
> shortcut  
> that we used above to start a command prompt with the right environment  
> for  
> using ruby. However, if you want you set up your environment so that  
> it’s  
> always correct for running ruby from the command line, so that you can  
> use a  
> regular command prompt to run ruby programs instead of needing to use  
> the  
> specific shortcut that the installer gave you.

---

<div class="post-metadata">

**Author:** ![karlhoover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4da419/32.png) [@karlhoover](https://www.ruby-forum.com/u/karlhoover)\
**Post date:** [July 26, 2010, 12:45am UTC](https://www.ruby-forum.com/t/basic-beginner-help-needed/192152/7 "2010-07-26T00:45:43Z")

</div>

Thank you all for your input. After reading the comments I took the  
advice of reading the two on-line tutorials, so this is where I am now:  
I have switched to a different computer that has the Windows XP  
operating system, have installed Ruby 1.9.1 on it (with ruby.exe located  
in â€˜C:\Ruby191\binâ€™), I downloaded and installed the SciTE editor  
recommended by Mr. Neighborlyâ€™s Humble Little Ruby Book, and have been  
successful in getting the SciTE editor to open scripts located in  
â€˜C:\Documents and Settings\Karl Halvorson\My Documents\Ruby\My Ruby  
Tutorial scriptsâ€™. The tutorials with this editor started out fine, I  
entered the text

puts “Hello, World.”

Into the text editor, pressed go and got

> ruby hello.rb  
> Hello, World.  
> Exit code: 0

To me that looked like it worked the way it was supposed to.  
I then went on to the next step and typed the following into the text  
editor:

puts “Hello, World. What is your name?”  
myname = gets()  
puts "Well, hello there " + myname + “.”

I was instructed to save the file again, so I did, as hello2.rb, and ran  
it again from the editor by pressing go. What I returned in the right  
pane of the editor was:

> ruby hello2.rb

Also, the Windows Command Prompt opened up with  
â€˜C:\Ruby191\bin\ruby.exeâ€™ at the top in the menu bar, but nothing in the  
black screen except for a blinking cursor (see attached image1). I tried  
typing in the black screen, but was unable to. The tutorial stated, â€œyou  
should see a greeting, be asked for your name, and then greeted by  
name.â€ None of this happened.

Any suggestions what to try next?

Also, Phaneee5, could you explain, in beginner language (step-by-step)  
what you mean by â€œSetting the PATH environment variable to the ruby-\>bin  
folderâ€, for this is not covered in any of the biginning tutorials that  
I have read? The part I really donâ€™t understand is â€œAdd this path to the  
PATH environment variable.â€ The path to ruby.exe on my computer is  
â€˜C:\Ruby191\binâ€™, but what exactly is the â€˜PATH environment variableâ€™?  
and how exactly do I add â€˜C:\Ruby191\binâ€™ to it?

Thank you all again for your help.

Phani Medicharla wrote:

> Hello Karl,
> 
> Try going through these books to get started in Ruby -  
> [http://www.humblelittlerubybook.com/book/hlrb.pdf](http://www.humblelittlerubybook.com/book/hlrb.pdf)  
> [http://www.sapphiresteel.com/The-Book-Of-Ruby](http://www.sapphiresteel.com/The-Book-Of-Ruby)
> 
> I have quoted these as they are readily available on the internet for  
> free. And as pointed out by Heruacles, posting the code snippet with  
> which you have a problem will help the forum give you better answers.
> 
> After you write code in notepad (try notepad++ or any other code editor  
> which will give you syntax highlighting, this will help you learn  
> easily) save the file with a .rb extension anywhere on your computer  
> (have a separate folder for this to keep your ruby files in one place).
> 
> Setting the PATH environment variable to the ruby-\>bin folder helps you  
> launch the ruby interpreter from the command line (from any path). If  
> you have installed ruby in your C drive for e.g., the bin dir would be  
> c:\ruby-1.9.1\bin  
> Add this path to the PATH environment variable.
> 
> After this, you can open command prompt, navigate to the path where you  
> saved your ruby file and type ‘ruby filename’. For e.g, if you have  
> saved your file in a folder called ‘my scripts’ on D with the name  
> ‘first.rb’, you must type the following in the command prompt  
> D:\my scripts\>ruby first.rb
> 
> Karl Halvorson wrote:
> 
> > I am new to Ruby and have been looking for some basic beginner help. I  
> > have not been able to find a beginner forum anywhere, so I apologize if  
> > this is too basic a question for this group. I have installed ruby  
> > 1.9.1 on my windows 7 pc and have had success using interactive ruby  
> > (and the Windows command prompt). Where I am stuck is creating a script  
> > in notepad and then running that script. It seems a bit peculiar to me  
> > that all the beginning tutorials that I ahave tried just say to create  
> > these scripts, but they donâ€™t mention where they need to be saved. I  
> > also have not come across any tutorials that cover configuring the ruby  
> > file path. I believe I have written and named the scripts properly, but  
> > when I try to open them, I get the error message:
> > 
> > NameError: undefined local variable or method â€˜helloâ€™ for main:Object  
> > from (irb):1  
> > from C:/Ruby191/bin/irb:12:in â€˜â€™
> > 
> > Any help would be much appreciated.
