A more elegent solution in Ruby ;-)