Ruby implementation
Refactor Ruby solution; fix output to meet spec