Things You'll Need:
- Ruby interpreter
- Keyboard
-
Step 1
Open up any text editor, such as notepad, wordpad or SciTE. Ruby code can be edited using any editor that outputs plain text.
-
Step 2
Type in the following code:
puts "What is your name?"
name = gets.chomp
puts "Hello " + name + "!" -
Step 3
The "puts" function in ruby will print data to the screen, followed by the enter key or newline. This results in a prompt "What is your name?" for the user to answer. The "gets" function that we call immediately after reads data from the keyboard, and stores it in the variable "name". the ".chomp" will clear off the newline character created when the user pressed the enter key to type in data. We then print the stored data back out to the screen with a nice message.
-
Step 4
Save your file as "myprogram.rb" and then open up a command line prompt. Change directory (cd) to the location where you saved your file, and then type "ruby myprogram.rb" to watch your program run.














