ruby refactor