It seems to be a more generic and Ruby idiomatic solution. Feel free to make change. I am new to github (and Ruby), please let me know if there is anything I need to do with the pull request or this patch.