this works - checkout the answers and see a simpler option that Ruby provides for implementing this functionality.