Created
October 30, 2012 20:50
-
-
Save uhlenbrock/3982945 to your computer and use it in GitHub Desktop.
Refactor a type implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###---------------------------------------------------- Class Methods | |
def sale_type | |
@sale_type ||= Sale.sale_type_ids[ self.sale_type_id - 1 ][0] | |
end | |
###---------------------------------------------------- Class Methods | |
def self.sale_type_ids | |
[ | |
['Personal Property', 1], | |
['Consignment', 2] | |
] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###---------------------------------------------------- Class Methods | |
def sale_type | |
@sale_type ||= Sale.sale_type_ids.detect { |t| t[:id] == sale_type_id }.try(:name) | |
end | |
###---------------------------------------------------- Class Methods | |
def self.sale_type_ids | |
{ | |
{ id: 1, name: 'Personal Property' }, | |
{ id: 2, name: 'Consignment' } | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment