Working example for you: http://rubyfiddle.com/riddles/22ff9