class Money def zero? self.cents.zero? end def to_f self.cents / 100.0 end %w(abs ceil floor round).each do |method| define_method(method) do self.class.new(@cents.send(method), self.currency) end end def to_liquid format(:with_currency) end def self.penny @penny ||= Money.new(1) end def self.zero @zero ||= Money.empty end end class Integer def to_money(currency=Money.default_currency) Money.new(self, currency) end end class Float def to_money(currency=Money.default_currency) Money.new((self * 100.0).ceil, currency) end end