add more elegant solution + ruby