Ruby solution