
I've been reading the book Everyday Scripting with Ruby which was written by Brian Marick from Pragmatic Programmers, originally called Scripting for Testers, for the past couple of weeks and going working through the examples in the book to get a better grasp of ruby. I think this is the first time I've read a book written for programmers from other languages who want to get a better understanding of ruby, while getting to do some cool exercises to learn some more of the ruby magic. None of that nasty PHP way of doing things which rely on having silly settings turned on in your php.ini and that you hope you will figure out why something is not working to realise that you don't have register_globals on for example.
The approach Brian Marick takes is quite different from the various perl, python and PHP books I've read in the past, so that was quite refreshing that he has included various techniques that one can use everyday in your ruby programming. Having previously written some ruby utilities to do simple things the svnannounce, which basically sends commit messages to jabber recipients, I particularly enjoyed the learning how to write the code churn calculator as well as using the watchdog code with having multiple methods of sending messages out which I will look into extending svnannounce to handle sending svn commits to twitter, msn, etc.
The book is divided up into multiple sections starting with The Basics, Growing a Script, Working in a World Full of People, and The Accomplised Scripter.
The ruby facts chapters through out the book, I found quite informative as Brian explains various rubyisms like arrays, classes, booleans, hashes, modules, etc. which I've found cleared up quite a number misunderstandings I had with the ruby language having dived in and just started coding simplish things.
The scraping webpages section was fun. I've in the past written some nasty PHP code to scrape pages for part of a ISP Management console I wrote during where I'd scrape various pages on UUnet, now Verizon, dialup management console to see number of dial-up users online, users session history, etc. And need I mention that you use a lot less code with ruby than with PHP. Learning how to use regular expressions and the ruby xpath library was quite cool. The Xpath stuff sort of reminds me of python's beautiful soup for liquidising webpages.
I'm actually estactic that CSV file parsing in Ruby is so much easier than PHP. Numerous things I do utilise some form of file containing data that needs to be processed or exported. I've started porting a PHP reporting tool over to ruby and using ruby on rails for the web interface portions. Being able to natively write CSV files which export data in the correct order in ruby when working with arrays is fantastic.
It's actually great working through a excellent book for learning a language, having useful examples to learn the language and not just your usual build a basic shopping cart type examples but real world style examples to learn certain nifty features like argument lists for passing multiple arguments to a method without.
Things like learning how to structure your directories when creating a library for ruby and finding out if you'll have name clashes. Things like including modules within other modules has given me some ideas. There is seriously more magic available in ruby which is quite powerful compared to PHP.
A great way to learn how to automate tasks using ruby. Even touches a little bit on rake files, gems, bulk updating gems, and a lot more.