Mac OS X

If you’re using OS X, you’re in luck! You can use the best (in my opinion) text editor, Ruby is already installed for you in OS X 10.2 (Jaguar) and up, and you get to use a real command line (not that silly wanna-be command line we have to use on Windows)!

My absolute favorite editor is TextMate (http://macromates.com/). It’s cute, it’s sweet, and it has great Ruby support. The only drawback is that it’s not free. But if you code as much as I do, it’s worth the (fairly cheap) price. And if you’re using a Mac, then I assume you are accustomed to getting the best…and paying for it! In any case, it has a fully functional free trial, so you can give it a try if you want. If you really need a free text editor, though, try TextWrangler (http://www.barebones.com/products/textwrangler/). It gets the job done.

Next, you should make a folder on your desktop in which to keep your programs. Right-click (oops! I mean Ctrl-click) on your desktop, and select New Folder. You want to give it a name both descriptive and alluring, such as programs. Nice.

Now, let’s get to know your computer a little better. The best way to really have a one-on-one with your computer is on the command line. You get there through the Terminal application (found in the Finder by navigating to Applications/Utilities). Open it, and you’ll see something like this:

Last login: Sat Oct 8 12:05:33 on ttyp1
Welcome to Darwin!
mezzaluna:~ chris$​ _

(That cursor at the end might be blinking, and it might be a vertical line instead of an underscore. Whatever it looks like, it’s your computer’s way of asking “What would you like?”)

It’s telling me when I last logged in (though if it’s your first time, it might not say that), welcoming me to Darwin (the deep, dark internals of OS X), and giving me a command prompt and cursor. Prompts, like West-Coast hairdos, come in a variety of shapes, sizes, colors, and levels of expressivity. This isn’t the prompt I normally use (nor is this the hairdo I normally use—I think this is the first time I’ve worn pigtails out of the house), but it’s the default prompt. It’s showing the name of this computer (“mezzaluna”), what two dots look like (“:”), something else I’ll tell you about in just a bit (“~”), who I am (“chris”), and then just a dollar sign (“$”). This is for good luck, I guess. Maybe it’s trying to give my name a little bling bling. I don’t know.

Anyway, here we are, at the command line, which is the heart and soul of your computer. You want to be somewhat careful what you do down here, since it’s not too hard to do Bad Things here. (It’s easier to delete everything on your computer than it is to get rid of that dollar sign, for example.) But if you don’t try anything too rambunctious, you should be fine.

Here you are, basically just staring at your computer naked. It would only be polite to say “hello” at this point, so type echo hello on the command line, and press Return. Your computer should reply with a friendly hello as well, making your screen look something like this:

mezzaluna:~ chris$​ echo hello
hello
mezzaluna:~ chris$​ _

And your cursor is blinking again in a “What’s next?” sort of way. Now that you’re acquainted, ask your computer whether it has Ruby installed and, if so, which version. Do this with ruby -v:

mezzaluna:~ chris$​ ruby -v
ruby 2.0.0p195 (2013-05-14) [universal-darwin9.0]

That’s good—I have Ruby 2.0.0 installed. If you have an earlier version, you can still use it, but a few examples in this book might not do exactly the same thing for you. (Almost everything should work, though.)

Now that Ruby is ready to rumble, it’s time to learn how to get around your computer from the command line and what that ~ in the prompt is all about.

The ~ is just a short way of saying “your home directory,” which is just a geek way of saying “your default folder,” which is still kind of geeky anyway. And I’m OK with that.

That’s where you are: your home directory. If you want to change to a different directory, you use cd. (No one wants to type change-directory, not even once. I mean, I had to just then, to make a point, but in general you really don’t want to type it.)

mezzaluna:~ chris$​ cd Desktop
mezzaluna:~/Desktop chris$​ _

So, my prompt changed, telling me that I’m now on my desktop, which is itself in my home directory. (Notice that Desktop was capitalized. If you don’t capitalize it, your computer will get angry and begin to swear at you in computerese, with such insults as “No such” and “file” and the worst one of all: “bash.”) You can go back up a directory with cd .., which in this case would put you back in your home directory. And at any time, if you just type cd by itself, that takes you to your home directory, no matter where you are. This is just like the Return spell in Dragon Warrior (the original Dragon Warrior; I don’t play any of these new-fangled “fun” versions…).

But we don’t want either of those. We want to go to your programs folder (or directory, or whatever). Assuming you’re still in your Desktop folder (if not, get there quick!), just do this:

mezzaluna:~/Desktop chris$​ cd programs
mezzaluna:~/Desktop/programs chris$​ _

But you probably could have guessed that.

As they say here in Norway: “Bra!” (See why I like it here? I’m not even allowed to tell you what they say for “five” and “six.”) Now you’re ready to program.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.228.19