Ruby refactoring