Refactoring exercise on Ruby