Category Archives: ruby

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.


Anyone Can Program: 1-Introduction

Anyone can program.  There’s a reason programmers use something called a “programming language.”  Programming is nothing more than telling the computer to do what you want in a language it understands.  Just like you can understand English, you can learn to understand  any programming language out there.  People learn new languages every day, so why can’t you?

The first step is to not be intimidated by what you might have heard about programming.  Programming code (the word used to represent stuff written in a programming language) does not look like this:

Matrix Code

It looks like this:

print "Hello World"

Compare that to this: “La programación es fácil.” or “Программирование легко.” or even “編程容易。”

Learning a programming language is often easier than learning a different spoken language.  Every programming language out there is actually some form of english.  Like the preceding example shows, to print the words “Hello World” to the screen, you would type ‘ print “Hello World”.’  You may not understand how or why this works yet, but it’s a lot more understandable than any of the other languages I showed.

So Let’s Do It

Alright, let’s just quickly cover a few basics about what a programming language really is, then we’ll get cracking.

All computers speak a single language, called binary, which consists entirely of 0’s and 1’s. Because it can take thousands of 0’s and 1’s to write a simple sentence in computer language, programmers came up with special programming languages. These languages are understandable by humans, but can be easily translated into the computers’ native language of binary.

Hello World in Binary

Of course, when I say “translated” I mean that another computer program (often called an “interpreter”) comes along and translates our programming statements. There are many different interpreters out there. All of them speak binary, but they all speak a different programming language. Let me introduce you to some of these interpreters:

Ruby, Perl, and Python

Python’s a slick character and, as you can see, a big fan of white empty spaces. We’re not going to learn his native language because I can’t draw a snake very well. Perl is an interesting guy, but it’s really hard to tell what’s going on behind that shiny head of his. In fact, only those who know him well really understand what he’s saying. Ruby is really cool guy. You can tell he’s cool because he’s wearing sunglasses and he’s on a motorcycle. We’re going to learn Ruby’s language because we want to be cool like him.

So to summarize: Programming languages are easily understandable by humans and are converted into computer language (binary) by interpreters. There are many different interpreters, and each one speaks a different programming language. We’re going to learn Ruby’s language because it’s so totally awesome.

Merb Jaunt Graphic (PDF)

It’s high time I had a blog. We’ll start this off with a little diagram I made of the Merb request flow. Simply a graphical representation of Ezra’s excellent post.Is their anything else you think I should add?