Ruby is an expressive, very high-level, scripting language. It is used on the Web mainly as part of the Ruby on Rails web development framework, but also standalone. If you’re curious about what Ruby (not Ruby on Rails) feels like, you don’t necessarily need to pick up a book or go watch a screencast (although those are good ways to learn, too).
Below are three fun, simple ways in which you can try Ruby in your browser, right now, for free, without installing a single file.
Hailing all the way from India, Rubymonk offers a series of over 50 short, interactive Ruby exercises and it saves your progress. Above is what I saw when I went back to Rubymonk after leaving the website (I solved the first couple of exercises).
Let’s look at what a single exercise looks like:
The exercise starts with a simple explanation, followed by a snippet of code. If you hit the Run button, the code is immediately evaluated and you get to see its output. Next, you get a simple assignment. Write the code you think is the right answer, and hit Ctrl+Enter to run it (or click the Run button). The Rubymonk now spits out an answer:
Once you finish working through some of the exercises, you will be presented with a problem to solve on your own:
You get an explanation of what you need to solve, some template code to get you started, and you’re on your own. This is great, because it’s much closer to actually coding than filling in one-liners in response to narrow questions. If you get stuck, you can always click “See the Solution” and the solution will instantly appear in the text box.
Once you’re done with the first problem, you are transported to the table of contents, where you can pick and choose what you want to learn (and whether you want a lesson or a problem). Lessons look like this:
And a problem looks like this:
The tags are lessons which you should work through, in order to acquire the skills you need to solve the problem. The whole thing is very polished, and just generally fun to work with. Highly recommended.
The Ruby Koans are hosted over at Heroku, and are even more steeped in mysticism that Rubymonk. Check it out:
Say what you will, but this is definitely not boring. Fill in what you think is the right answer (trivial, in this case), and hit Enter. The snippet will be evaluated, and colored accordingly:
Try Ruby was created as a tribute to why’s (poignant) guide to ruby (link to PDF), one of the craziest programming textbooks I have ever laid eyes on. It’s a great book for the Ruby language, and although the author no longer takes an active role in the Ruby community, I have a feeling he would have approved of the project. The website is built as a large ruby prompt, with instructions on the side:
The text is simple and playful (no mystical references here). You type real Ruby code in the prompt, and work through the simple exercises one by one. The whole thing doesn’t take very long.
Personally, I feel that learning by doing is one of the best ways to absorb new material. These may not make you into a code ninja, but they will definitely give you a feel for Ruby. If you’re curious about the language, pick the one you like best and take it for a spin! Let us know how it went in the comments.