Ruby rewrite