ruby rewrite