Read about Enumerable#inject, and think about refactoring this method.