Skip to content

Instantly share code, notes, and snippets.

@rafer
Created October 11, 2011 04:55
Show Gist options
  • Save rafer/1277328 to your computer and use it in GitHub Desktop.
Save rafer/1277328 to your computer and use it in GitHub Desktop.
class Product
def list_price=(price)
write_price(:list_price, price)
end
def sales_price=(price)
write_price(:sales_price, price)
end
private
def write_price(attribute, raw)
sanitizied = raw.to_s.gsub(/[^\d\.]/, '')
write_attribute(attribute, sanitizied)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment