Skip to content

Instantly share code, notes, and snippets.

@uhlenbrock
Created October 30, 2012 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uhlenbrock/3982945 to your computer and use it in GitHub Desktop.
Save uhlenbrock/3982945 to your computer and use it in GitHub Desktop.
Refactor a type implementation
###---------------------------------------------------- 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
###---------------------------------------------------- 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