I tried out Ruby on Rails for the first time today. My spare time (what little remains of it) has been divided between playing with my websites, and playing with Ruby. So I figured why not combine the two.
It's somewhat infuriating when I can start from scratch and make something in 15 minutes in Rails that works as well as the huge mess of PHP crap that it took me over a week to write. My previous web host didn't have Ruby, so I was forced to use PHP by necessity. PHP4, of course. Blech. Is there anyone on this planet who uses PHP by choice?
I briefly toyed with the idea of using Smarty. It seems like a nice templating system, with its only weakness being that you have to use PHP to use it.
On a different topic, this week's Ruby Quiz was amusing. The problem is essentially to split a string in every possible way (with varying split length, with some upper bounds on split length), transform the parts, recombine them, and then print or process the result. A recursive solution is very straightforward: split the string into a little left part and a big leftover right part, transform the left part, then recursively process the right part in the same way. I wrote up a solution that's about 20 lines long. But it's slow as heck.
Reading other people's solutions, I noticed a neat thing about recursion in Ruby. There are two different ways of doing this recursively. One way (the slow way and memory-intensive way, the way I did it) is to recurse all the way to the base case (run out of leftovers to process), leaving your transformed bits of string scattered all over your call stack. Then return all the parts back up the call stack putting them together as you go. When you've hit the very top of the stack again, you'll have a huge accumulated list (array) of all the results.
But another way is to pass the partly-processed and unprocessed parts of the string both down the call stack as parameters in your method; each method call eats a bit of the unprocessed part and adds a bit to the processed part and then both are passed along again. The base case is once your unprocessed part is empty. If you also pass a Ruby block along as you recurse, then when you hit the bottom of the call stack, you can yield your accumulated fully-processed result to the block. This way you don't have to collect all the results into an array before returning them. You can yield the results as soon as you compute them, one-by-one. I thought it was neat.