2008-08-10

Let's start

OK, all blog options are set up like they should, page layout is chosen, colours are adjusted. Probably it's time to write the first post here. As you might have guessed, this blog is going to be about Ruby - an interesting, inspiring, very easy and very complicated at the same time, programming language. That sentence should make it as an introduction, and let's close this topic for now.

If you are a beginner, then that's the best place for you to start. I'll try to gather some interesting beginner tutorials and useful info, and also some of my knowledge. I will also post on where to download and how to install Ruby and some useful modules. I hope that will help you a bit at the beginning.

If you are an expert... well, I'm and expert too. I guess if you are here, then your knowledge lacks some parts, as usually experts' knowledge does, not excluding my own. If what I know fits what you don't, I'll be glad to have helped you. And I'm sure I can, here or there. The problem for now is that I have to start off with the whole bunch of beginner things, and then I will get back to what's really fascinating about Ruby.

Tutorials
So let's tackle some real problem. How to start with Ruby? First, please try it out, if you haven't done it yet: A Hands-on Ruby Tutorial! It's really cool to start with it - you don't have to install anything, and you have access to the real programming and not some "now imagine that we do this and get this." Start with typing 'help' and then just follow the tutorial.

You might also want to try this (non-interactive) tutorial about "object-orientedness" of Ruby: Tutorial.

Get a console of your own
Once you see (I'm sure you do!) that there's something in it, I have great news for you! You can have a console just like the one on the webpage, only better, right on your computer! Do you think I'm using Window's calc anymore? Believe me, I don't. So: if you are using Windows, go here and download the last stable release (at the time of writing it is ruby186-26.exe). Install it, but choose carefully the path! I suggest installing it in something like C:\Ruby\Ruby\, and that's because you might want to store your programs in C:\Ruby\Programs\, your gems (about these later on) in C:\Ruby\Gems\, etc. But as you prefer. But remember, never put your own files in the installation directory. They might not survive a Ruby version upgrade. During the installation, always agree to the default options, they are reasonable.

Once you finished the installation, let's get to the Ruby console I promised you. Open the Windows console (Start | Run, cmd, Enter) and type irb, Enter. If this appears: irb(main):001:0> then here you are, the console is ready! If an error occurs instead, you will have to add the Ruby binaries path to your environment path variable. Right-click My computer on your desktop, Properties | Advanced | Environment variables, locate Path on the bottom list, Edit, and add to it ;C:\Ruby\Ruby\bin or something else if you installed Ruby elsewhere. Accept changes, close the console, open it again and try to run irb, it should work now.

If you want to have quick access to your irb, right-click on the desktop, New | Shortcut, and as the element to run type %windir%\system32\cmd.exe /k irb.bat and accept. (It is better to do it like this and not just link to the irb because if you happen to get an error that closes irb, you can still read the error message because the window won't close. What could cause such a terrible error that closes irb? Oh, if you must know, type
STDOUT.close
)

Now I'll leave you with your new toy. Play with it and explore. Here's a nice spec of basic Ruby objects like Arrays and Strings, have a look: Ruby Class Reference. Another tutorial: Why's... but... be careful with this one...

In the next post we will start up the rubygems which you are likely to need later. In following posts, I will present interesting classes, modules and functionalities, both in the standard Ruby distribution, and in the additional modules. That's all for today, see you!

No comments: