Sha256: 8bcb26d10f5b76128cd72845e140688ae4818b7f3268ecb1db2230d993e3e91e
Contents?: true
Size: 1.93 KB
Versions: 9
Compression:
Stored size: 1.93 KB
Contents
class Money module Constructors # Create a new money object with value 0. # # @param [Currency, String, Symbol] currency The currency to use. # # @return [Money] # # @example # Money.empty #=> #<Money @fractional=0> def empty(currency = default_currency) @empty ||= {} @empty[currency] ||= new(0, currency).freeze end alias_method :zero, :empty # Creates a new Money object of the given value, using the Canadian # dollar currency. # # @param [Integer] cents The cents value. # # @return [Money] # # @example # n = Money.ca_dollar(100) # n.cents #=> 100 # n.currency #=> #<Money::Currency id: cad> def ca_dollar(cents) new(cents, "CAD") end alias_method :cad, :ca_dollar # Creates a new Money object of the given value, using the American dollar # currency. # # @param [Integer] cents The cents value. # # @return [Money] # # @example # n = Money.us_dollar(100) # n.cents #=> 100 # n.currency #=> #<Money::Currency id: usd> def us_dollar(cents) new(cents, "USD") end alias_method :usd, :us_dollar # Creates a new Money object of the given value, using the Euro currency. # # @param [Integer] cents The cents value. # # @return [Money] # # @example # n = Money.euro(100) # n.cents #=> 100 # n.currency #=> #<Money::Currency id: eur> def euro(cents) new(cents, "EUR") end alias_method :eur, :euro # Creates a new Money object of the given value, in British pounds. # # @param [Integer] pence The pence value. # # @return [Money] # # @example # n = Money.pound_sterling(100) # n.fractional #=> 100 # n.currency #=> #<Money::Currency id: gbp> def pound_sterling(pence) new(pence, "GBP") end alias_method :gbp, :pound_sterling end end
Version data entries
9 entries across 9 versions & 1 rubygems