this code is one way to implement the functionality - take a look at the answers - Ruby provides some ways to simplify the code.