Ruby: Remove some duplication