Anyone Can Program: 2-Say Hello to Ruby

The first thing we need to do is put a copy of the Ruby Interpreter on your computer. In order to talk to the interpreter, programmers use something called The Command Line. The command line is, oddly enough, a line where you type in commands. To talk to Ruby, all you do is type the word “ruby” and then whatever commands or programming statements you want it to translate into computer lingo (binary.) Here’s how to use ruby with the command line:

If You’re Using Windows

Click here to download a program that will install everything you need to use Ruby. Double click on the installer to start it up, and press “Next” a bunch of times to finish the installation. Once that’s done, click on the Start menu and click on the option that says “Run…”. Then, type the word “cmd” in the popup box and press “Ok.” The thing that should pop up after that is the Windows Command Line.

Windows Command Line (Prompt)

If You’re Using a Mac

Macs already have ruby installed on them. To start the mac command line, go to the “Applications” folder (where all your programs are) and open the “Utilities” folder. Inside of “Utilities,” double click on the program named “Terminal” to start the OS X Command Line.

Mac OS X Terminal - Command Line

This is it, you’re now ready to begin talking to the ruby interpreter. Type in the word “irb” and press enter. You have now entered into an interactive conversation with our buddy Ruby (“irb” stands for Interactive Ruby.) Let’s tell the computer to say hello to us:

print "Hello World"

(Whenever you see stuff that looks this, that means that it’s real live programming code and you can type it directly into irb.)

If all is well, ruby should hear you loud and clear and respond with something like: “Hello World”.

It didn’t, did it? Instead you probably saw “Hello World=> nil”, which is almost but not quite what we told the computer to say. What you have to remember is that programming is like speaking a language and, unless you’re speaking to a wall, someone is usually going to respond to what you say. That little “=> nil” at the end is ruby’s response to what you told it to do.

Understanding the response will take some time, so for now we’re just going to do that thing men are good at and ignore the other side of the conversation (if you’re a woman, don’t worry, “=> nil” is Ruby’s way of saying it has nothing intelligent to say – like when men grunt.) To make it easier on us, we’re going to use a slightly different command that makes it easier to ignore Ruby’s responses.

puts "Hello World"

Now you should see:

Hello World
=> nil

Ruby’s being considerate and stating his half of the conversation on the next line, where we can conveniently ignore it.

To Summarize: Like normal conversations, there are usually responses to the things you say. Every statement in the Ruby language produces a corresponding response from the computer.


3 responses to “Anyone Can Program: 2-Say Hello to Ruby

  1. Sorry,

    Now I see the properties described. I didn’t realize that there was more to this tutorial.


  2. No worries, John.

    If you have any questions about installing or setting up Ruby, feel free to ask them here and I’ll do my best to answer them.

  3. Somehow i missed the point. Probably lost in translation 🙂 Anyway … nice blog to visit.

    cheers, Yvette

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s