Rewrite in Ruby