Rewrite bin script in ruby