Rewriting the ruby inject method