Skip to content

Instantly share code, notes, and snippets.

@trappist
Created March 5, 2018 20:56
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 trappist/2cf6f53f6ab95a616b39f1b0ae43ed00 to your computer and use it in GitHub Desktop.
Save trappist/2cf6f53f6ab95a616b39f1b0ae43ed00 to your computer and use it in GitHub Desktop.
module Concerns
module Gmoney
extend ActiveSupport::Concern
included do
def self.gmoney(*attrs)
attrs.each do |attr|
define_method(:"#{attr}=") do |money|
if money.blank?
self[attr] = 0.0
elsif money.is_a?(String)
self[attr] = money.gsub(/[\$,]/, '').to_f
else
self[attr] = money
end
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment