Tip #10 - The Ruby Language

2008-04-17 07:40:40 +0000

Learning Rails is hard enough without also facing the task of learning Ruby at the same time. Here I go over some of the must knows in Ruby so that you get some basic understanding of how to do Rails.

This is part of my 8-Part tip-a-thon on the Must Know Facets of Ruby on Rails. If you haven’t already, please read the first part and then come forward (there is a link at the bottom of each article that links to the next)

Learning Ruby

Ruby is fun.

You have probably heard that, you have also probably heard that Rails is fun. Both are true.

But there is nothing fun about tearing your hair out online trying to figure out why a piece of code doesn’t work, especially if you can’t even read the code!

So Learning Ruby is probably the most important step to becomming a Ruby on Rails developer.

But how do you do that?

Well, this is how I did it.

Read… — LOTS

If you don’t already own the Pickaxe, then you should go and get it. If you are just looking to see if Ruby is for you, then maybe you could read the online edition of Version 1 of the Pickaxe. It is older, but contains enough information and is current enough to be worthwhile. Ruby hasn’t changed that much since the version 1 and all the basic concepts are the same.

You can read through _why’s (who is basically Ruby’s mad scientist) Poignant Guide to Ruby on learning Ruby. I must admit, I tried, I did… but it lost me about the time the Fox/Dog/Crazy thin dude lost is truck and someone had stolen it… you’ll need to have a look and read to see what I mean :)

There are many other fine Ruby books out there as well. I can also recommend the O’Rielly book, mainly because it has a different approach to the Pickaxe and gives you a different view of the same problem.

If you read through these books, and do the examples (the Pickaxe is good for this as you build a Jukebox as you go!) you will get some good basic understandings about how Ruby ticks.

Use Ruby Everywhere you Can

This is a key one. When you are first learning Ruby, and you need to do something outside of Rails that could use a bit of shell scripting or some basic programming, use Ruby!

There is pretty much no task that Ruby can’t handle. I have used it to parse incomming emails, used it to merge CSV files together and also used it to clean up bad code points in a supposed unicode file.

I have even used it to help handle someone attacking one of our servers.

Once you decide you can use Ruby, go for it and learn all the little tricks inside of that big box called the standard library. There is so much in there that you can use and you will be surprised at how many tools you have at your disposal.

Practice with a different paradigm

Ruby on Rails is one use for Ruby and a very exact use. But following on from the previous point, try Ruby in different paradigms.

What do I mean? Well, make a server in Ruby that serves messages of any type over a network stack. Make a program that searches your hard drive for files, make something that plays some music. Really, anything.

When I did this I found that my understand of how Ruby on Rails works expanded a huge amount. Rails is just one medium sized Ruby program that handles routing, talks to your database and allows you to serve up web pages. Once you know how all the Ruby stuff fits together, you will understand Rails a lot more.

Next Up

Next in the series is the HTML and HTTP are Your Friends

blogLater

Mikel