Ruby Prime number algorithm