updated ruby solution