Learning Ruby with Rubywarrior

2 minute read

One of the things I really love about the ruby community is its inherent sense of fun. Beside the fact there are a lot of really smart, talented and very creative devs in it and at the RailsCamps (at least here in Aus), and some of the best stuff is just the things they whip up in their more whimsical moments.

One of these has to be rubywarrior (thanks to <Ritchie K. for introducing me to this one at Railcamp 7 in Canberra). Written by Railscasts stalwart Ryan Bates it’s there to teach you Ruby. And it rocks.

The scenario is that you’re a warrior that gets set a set of tasks each time and must write a method to get you through the scenario each time. You run the scenario and see if you’re successful.

sudo gem install rubywarrior

will get you the program installed on your machine

cd into a directory where you tend to keep your source files and run the command rubywarrior.

Welcome to Ruby Warrior
No rubywarrior directory found, would you like to create one? [yn] y
[1] beginner
[2] intermediate
Choose tower by typing the number: 1
Enter a name for your warrior: RubyNewb        
First level has been generated. See the rubywarrior/rubynewb-beginner/README for instructions.

So, cd into the rubywarrior/rubynewb-beginner/README and open it however you like to do that (textmate is best if you’re on a mac) and you’ll note it gives you a scenario and usually a hint at how to modify the play_turn method you’re responsible for to get through the scenario. You modify your player.rb file and the play_turn method, save it and then run the command rubywarrior in your directory. That runs the turns through a fun little text animation and if you are successful in completing the level you get a nice message, some points, and proceed to the next level where the README file has changed and given you a new scenario to overcome.

It’s a very simple way to learn actually and is a bit like a simple brainteaser to get through each level.

Definitely recommend it if you want to learn basic Ruby (there is also an intermediate level available if you think you’re hot stuff) and especially if you’ve come to Ruby through learning Rails first.

dev ruby