Class: Money
- Inherits:
-
Object
- Object
- Money
- Includes:
- Comparable
- Defined in:
- lib/money/money.rb,
lib/money/currency.rb,
lib/money/bank/base.rb,
lib/money/bank/variable_exchange.rb
Overview
Represents an amount of money in a given currency.
Defined Under Namespace
Modules: Bank Classes: Currency
Class Attribute Summary collapse
-
.default_bank ⇒ Money::Bank::*
Each Money object is associated to a bank object, which is responsible for currency exchange.
-
.default_currency ⇒ Money::Currency
The default currency, which is used when
Money.new
is called without an explicit currency argument.
Instance Attribute Summary collapse
-
#bank ⇒ Money::Bank::*
readonly
The
Money::Bank
based object used to perform currency exchanges with. -
#cents ⇒ Integer
readonly
The value of the money in cents.
-
#currency ⇒ Currency
readonly
The currency the money is in.
-
#exact_number ⇒ Object
readonly
Returns the value of attribute exact_number.
Class Method Summary collapse
-
.add_rate(from_currency, to_currency, rate) ⇒ Numeric
Adds a new exchange rate to the default bank and return the rate.
-
.ca_dollar(cents) ⇒ Money
Creates a new Money object of the given value, using the Canadian dollar currency.
-
.empty(currency = default_currency) ⇒ Money
Create a new money object with value 0.
-
.euro(cents) ⇒ Money
Creates a new Money object of the given value, using the Euro currency.
-
.from_bigdecimal(value, currency = Money.default_currency) ⇒ Money
Converts a BigDecimal into a Money object treating the
value
as dollars and converting them to the corresponding cents value, according tocurrency
subunit property, before instantiating the Money object. -
.from_fixnum(value, currency = Money.default_currency) ⇒ Money
Converts a Fixnum into a Money object treating the
value
as dollars and converting them to the corresponding cents value, according tocurrency
subunit property, before instantiating the Money object. -
.from_float(value, currency = Money.default_currency) ⇒ Money
Converts a Float into a Money object treating the
value
as dollars and converting them to the corresponding cents value, according tocurrency
subunit property, before instantiating the Money object. -
.from_numeric(value, currency = Money.default_currency) ⇒ Money
Converts a Numeric value into a Money object treating the
value
as dollars and converting them to the corresponding cents value, according tocurrency
subunit property, before instantiating the Money object. -
.from_string(value, currency = Money.default_currency) ⇒ Money
Converts a String into a Money object treating the
value
as dollars and converting them to the corresponding cents value, according tocurrency
subunit property, before instantiating the Money object. -
.new_with_dollars(amount, currency = Money.default_currency, bank = Money.default_bank) ⇒ Money
Creates a new Money object of
amount
value in dollars, with givencurrency
. -
.parse(input, currency = nil) ⇒ Money
Parses the current string and converts it to a
Money
object. -
.us_dollar(cents) ⇒ Money
Creates a new Money object of the given value, using the American dollar currency.
Instance Method Summary collapse
-
#%(val) ⇒ Money
Synonym for
#modulo
. -
#*(value) ⇒ Money
Multiplies the monetary value with the given number and returns a new
Money
object with this monetary value and the same currency. -
#+(other_money) ⇒ Money
Returns a new Money object containing the sum of the two operands’ monetary values.
-
#-(other_money) ⇒ Money
Returns a new Money object containing the difference between the two operands’ monetary values.
-
#/(value) ⇒ Money, Float
Divides the monetary value with the given number and returns a new
Money
object with this monetary value and the same currency. -
#<=>(other_money) ⇒ -1, ...
Compares this money object against another object.
-
#==(other_money) ⇒ Boolean
Checks whether two money objects have the same currency and the same amount.
-
#abs ⇒ Money
Return absolute value of self as a new Money object.
-
#allocate(splits) ⇒ Array<Money, Money, Money>
Allocates money between different parties without loosing pennies.
-
#as_ca_dollar ⇒ Money
Receive a money object with the same amount as the current Money object in canadian dollar.
-
#as_euro ⇒ Money
Receive a money object with the same amount as the current Money object in euro.
-
#as_us_dollar ⇒ Money
Receive a money object with the same amount as the current Money object in american dollars.
-
#currency_as_string ⇒ String
Return string representation of currency object.
-
#currency_as_string=(val) ⇒ Money::Currency
Set currency object using a string.
- #decimal_mark ⇒ Object (also: #separator)
-
#div(value) ⇒ Money, Float
Synonym for
#/
. -
#divmod(val) ⇒ Array<Money,Money>, Array<Fixnum,Money>
Divide money by money or fixnum and return array containing quotient and modulus.
-
#dollars ⇒ Float
Returns the value of the money in dollars, instead of in cents.
-
#eql?(other_money) ⇒ Money
Synonymous with #==.
-
#exchange_to(other_currency) ⇒ Money
Receive the amount of this money object in another Currency.
-
#format(*rules) ⇒ String
Creates a formatted price string according to several rules.
-
#hash ⇒ Fixnum
Returns a Fixnum hash value based on the
cents
andcurrency
attributes in order to use functions like & (intersection), group_by, etc. -
#initialize(exact_number, currency = Money.default_currency, bank = Money.default_bank) ⇒ Money
constructor
Creates a new Money object of
cents
value in cents, with givencurrency
. -
#inspect ⇒ String
Common inspect function.
-
#modulo(val) ⇒ Money
Equivalent to self.divmod(val).
-
#nonzero? ⇒ Money?
Test if the money amount is non-zero.
-
#remainder(val) ⇒ Money
If different signs self.modulo(val) - val otherwise self.modulo(val).
-
#split(num) ⇒ Array<Money, Money, Money>
Split money amongst parties evenly without loosing pennies.
-
#symbol ⇒ String
Uses Currency#symbol.
- #thousands_separator ⇒ Object (also: #delimiter)
-
#to_f ⇒ Float
Return the amount of money as a float.
-
#to_money ⇒ self
Conversation to
self
. -
#to_s ⇒ String
Returns the amount of money as a string.
-
#zero? ⇒ Boolean
Test if the money amount is zero.
Constructor Details
#initialize(exact_number, currency = Money.default_currency, bank = Money.default_bank) ⇒ Money
390 391 392 393 394 395 |
# File 'lib/money/money.rb', line 390 def initialize(exact_number, currency = Money.default_currency, bank = Money.default_bank) @exact_number = exact_number @cents = exact_number.round.to_i @currency = Currency.wrap(currency) @bank = bank end |
Class Attribute Details
.default_bank ⇒ Money::Bank::*
Each Money object is associated to a bank object, which is responsible for currency exchange. This property allows you to specify the default bank object. The default value for this property is an instance if Bank::VariableExchange.
It allows one to specify custom exchange rates.
33 34 35 |
# File 'lib/money/money.rb', line 33 def default_bank @default_bank end |
.default_currency ⇒ Money::Currency
The default currency, which is used when Money.new
is called without an explicit currency argument. The default value is Currency.new(“USD”). The value must be a valid Money::Currency
instance.
40 41 42 |
# File 'lib/money/money.rb', line 40 def default_currency @default_currency end |
Instance Attribute Details
#bank ⇒ Money::Bank::* (readonly)
The Money::Bank
based object used to perform currency exchanges with.
21 22 23 |
# File 'lib/money/money.rb', line 21 def bank @bank end |
#cents ⇒ Integer (readonly)
The value of the money in cents.
11 12 13 |
# File 'lib/money/money.rb', line 11 def cents @cents end |
#currency ⇒ Currency (readonly)
The currency the money is in.
16 17 18 |
# File 'lib/money/money.rb', line 16 def currency @currency end |
#exact_number ⇒ Object (readonly)
Returns the value of attribute exact_number.
23 24 25 |
# File 'lib/money/money.rb', line 23 def exact_number @exact_number end |
Class Method Details
.add_rate(from_currency, to_currency, rate) ⇒ Numeric
Adds a new exchange rate to the default bank and return the rate.
363 364 365 |
# File 'lib/money/money.rb', line 363 def self.add_rate(from_currency, to_currency, rate) Money.default_bank.add_rate(from_currency, to_currency, rate) end |
.ca_dollar(cents) ⇒ Money
Creates a new Money object of the given value, using the Canadian dollar currency.
72 73 74 |
# File 'lib/money/money.rb', line 72 def self.ca_dollar(cents) Money.new(cents, "CAD") end |
.empty(currency = default_currency) ⇒ Money
Create a new money object with value 0.
57 58 59 |
# File 'lib/money/money.rb', line 57 def self.empty(currency = default_currency) Money.new(0, currency) end |
.euro(cents) ⇒ Money
Creates a new Money object of the given value, using the Euro currency.
101 102 103 |
# File 'lib/money/money.rb', line 101 def self.euro(cents) Money.new(cents, "EUR") end |
.from_bigdecimal(value, currency = Money.default_currency) ⇒ Money
Converts a BigDecimal into a Money object treating the value
as dollars and converting them to the corresponding cents value, according to currency
subunit property, before instantiating the Money object.
302 303 304 305 306 |
# File 'lib/money/money.rb', line 302 def self.from_bigdecimal(value, currency = Money.default_currency) currency = Money::Currency.wrap(currency) amount = value * currency.subunit_to_unit Money.new(amount.fix, currency) end |
.from_fixnum(value, currency = Money.default_currency) ⇒ Money
Converts a Fixnum into a Money object treating the value
as dollars and converting them to the corresponding cents value, according to currency
subunit property, before instantiating the Money object.
243 244 245 246 247 |
# File 'lib/money/money.rb', line 243 def self.from_fixnum(value, currency = Money.default_currency) currency = Money::Currency.wrap(currency) amount = value * currency.subunit_to_unit Money.new(amount, currency) end |
.from_float(value, currency = Money.default_currency) ⇒ Money
Converts a Float into a Money object treating the value
as dollars and converting them to the corresponding cents value, according to currency
subunit property, before instantiating the Money object.
Behind the scenes, this method relies on Money.from_bigdecimal to avoid problems with floating point precision.
275 276 277 |
# File 'lib/money/money.rb', line 275 def self.from_float(value, currency = Money.default_currency) from_bigdecimal(BigDecimal.new(value.to_s), currency) end |
.from_numeric(value, currency = Money.default_currency) ⇒ Money
Converts a Numeric value into a Money object treating the value
as dollars and converting them to the corresponding cents value, according to currency
subunit property, before instantiating the Money object.
This method relies on various Money.from_*
methods and tries to forwards the call to the most appropriate method in order to reduce computation effort. For instance, if value
is an Integer, this method calls from_fixnum instead of using the default from_bigdecimal which adds the overload to converts the value into a slower BigDecimal instance.
341 342 343 344 345 346 347 348 349 350 |
# File 'lib/money/money.rb', line 341 def self.from_numeric(value, currency = Money.default_currency) case value when Fixnum from_fixnum(value, currency) when Numeric from_bigdecimal(BigDecimal.new(value.to_s), currency) else raise ArgumentError, "`value' should be a Numeric object" end end |
.from_string(value, currency = Money.default_currency) ⇒ Money
Converts a String into a Money object treating the value
as dollars and converting them to the corresponding cents value, according to currency
subunit property, before instantiating the Money object.
Behind the scenes, this method relies on from_bigdecimal to avoid problems with string-to-numeric conversion.
216 217 218 |
# File 'lib/money/money.rb', line 216 def self.from_string(value, currency = Money.default_currency) from_bigdecimal(BigDecimal.new(value.to_s), currency) end |
.new_with_dollars(amount, currency = Money.default_currency, bank = Money.default_bank) ⇒ Money
Creates a new Money object of amount
value in dollars, with given currency
.
The amount value is expressed in dollars
where the dollar
is the main monetary unit, opposite to the subunit-based representation used internally by this library called cents
.
130 131 132 133 134 135 |
# File 'lib/money/money.rb', line 130 def self.new_with_dollars(amount, currency = Money.default_currency, bank = Money.default_bank) money = from_numeric(amount, currency) # Hack! You can't change a bank money.instance_variable_set("@bank", bank) money end |
.parse(input, currency = nil) ⇒ Money
Parses the current string and converts it to a Money
object. Excess characters will be discarded.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/money/money.rb', line 164 def self.parse(input, currency = nil) i = input.to_s # Get the currency. m = i.scan /([A-Z]{2,3})/ c = m[0] ? m[0][0] : nil # check that currency passed and embedded currency are the same, # and negotiate the final currency if currency.nil? and c.nil? currency = Money.default_currency elsif currency.nil? currency = c elsif c.nil? currency = currency elsif currency != c # TODO: ParseError raise ArgumentError, "Mismatching Currencies" end currency = Money::Currency.wrap(currency) cents = extract_cents(i, currency) Money.new(cents, currency) end |
Instance Method Details
#%(val) ⇒ Money
Synonym for #modulo
.
651 652 653 |
# File 'lib/money/money.rb', line 651 def %(val) self.modulo(val) end |
#*(value) ⇒ Money
Multiplies the monetary value with the given number and returns a new Money
object with this monetary value and the same currency.
Note that you can’t multiply a Money object by an other Money
object.
562 563 564 565 566 567 568 |
# File 'lib/money/money.rb', line 562 def *(value) if value.is_a?(Money) raise ArgumentError, "Can't multiply a Money by a Money" else Money.new(cents * value, currency) end end |
#+(other_money) ⇒ Money
Returns a new Money object containing the sum of the two operands’ monetary values. If other_money
has a different currency then its monetary value is automatically exchanged to this object’s currency using exchange_to
.
521 522 523 524 525 526 527 |
# File 'lib/money/money.rb', line 521 def +(other_money) if currency == other_money.currency Money.new(cents + other_money.cents, other_money.currency) else Money.new(cents + other_money.exchange_to(currency).cents, currency) end end |
#-(other_money) ⇒ Money
Returns a new Money object containing the difference between the two operands’ monetary values. If other_money
has a different currency then its monetary value is automatically exchanged to this object’s currency using exchange_to
.
540 541 542 543 544 545 546 |
# File 'lib/money/money.rb', line 540 def -(other_money) if currency == other_money.currency Money.new(cents - other_money.cents, other_money.currency) else Money.new(cents - other_money.exchange_to(currency).cents, currency) end end |
#/(value) ⇒ Money, Float
Divides the monetary value with the given number and returns a new Money
object with this monetary value and the same currency. Can also divide by another Money
object to get a ratio.
Money/Numeric
returns Money
. Money/Money
returns Float
.
585 586 587 588 589 590 591 592 593 594 595 |
# File 'lib/money/money.rb', line 585 def /(value) if value.is_a?(Money) if currency == value.currency (cents / BigDecimal.new(value.cents.to_s)).to_f else (cents / BigDecimal(value.exchange_to(currency).cents.to_s)).to_f end else Money.new(cents / value, currency) end end |
#<=>(other_money) ⇒ -1, ...
Compares this money object against another object. other_money
must respond to #to_money. Returns -1 when less than, 0 when equal and 1 when greater than.
If other_money
is a different currency, then other_money
will first be converted into this money object’s currency by calling #exchange
on other_money
.
Comparisons against objects that do not respond to #to_money will cause an ArgumentError
to be raised.
498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/money/money.rb', line 498 def <=>(other_money) if other_money.respond_to?(:to_money) other_money = other_money.to_money if self.currency == other_money.currency cents <=> other_money.cents else cents <=> other_money.exchange_to(currency).cents end else raise ArgumentError, "Comparison of #{self.class} with #{other_money.inspect} failed" end end |
#==(other_money) ⇒ Boolean
Checks whether two money objects have the same currency and the same amount. Checks against money objects with a different currency and checks against objects that do not respond to #to_money will always return false.
446 447 448 449 450 451 452 453 |
# File 'lib/money/money.rb', line 446 def ==(other_money) if other_money.respond_to?(:to_money) other_money = other_money.to_money cents == other_money.cents && self.currency == other_money.currency else false end end |
#abs ⇒ Money
Return absolute value of self as a new Money object.
681 682 683 |
# File 'lib/money/money.rb', line 681 def abs Money.new(self.cents.abs, self.currency) end |
#allocate(splits) ⇒ Array<Money, Money, Money>
Allocates money between different parties without loosing pennies. After the mathmatically split has been performed, left over pennies will be distributed round-robin amongst the parties. This means that parties listed first will likely recieve more pennies then ones that are listed later
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 |
# File 'lib/money/money.rb', line 1024 def allocate(splits) allocations = splits.inject(0.0) {|sum, i| sum += i } raise ArgumentError, "splits add to more then 100%" if allocations > 1.0 left_over = cents amounts = splits.collect do |ratio| fraction = (cents * ratio / allocations).floor left_over -= fraction fraction end left_over.times { |i| amounts[i % amounts.length] += 1 } return amounts.collect { |cents| Money.new(cents, currency) } end |
#as_ca_dollar ⇒ Money
Receive a money object with the same amount as the current Money object in canadian dollar.
982 983 984 |
# File 'lib/money/money.rb', line 982 def as_ca_dollar exchange_to("CAD") end |
#as_euro ⇒ Money
Receive a money object with the same amount as the current Money object in euro.
994 995 996 |
# File 'lib/money/money.rb', line 994 def as_euro exchange_to("EUR") end |
#as_us_dollar ⇒ Money
Receive a money object with the same amount as the current Money object in american dollars.
970 971 972 |
# File 'lib/money/money.rb', line 970 def as_us_dollar exchange_to("USD") end |
#currency_as_string ⇒ String
Return string representation of currency object
419 420 421 |
# File 'lib/money/money.rb', line 419 def currency_as_string self.currency.to_s end |
#currency_as_string=(val) ⇒ Money::Currency
Set currency object using a string
431 432 433 |
# File 'lib/money/money.rb', line 431 def currency_as_string=(val) @currency = Currency.wrap(val) end |
#decimal_mark ⇒ Object Also known as: separator
746 747 748 |
# File 'lib/money/money.rb', line 746 def decimal_mark I18n.t(:"number.format.decimal_mark", :default => currency.decimal_mark || ".") end |
#div(value) ⇒ Money, Float
Synonym for #/
.
606 607 608 |
# File 'lib/money/money.rb', line 606 def div(value) self / value end |
#divmod(val) ⇒ Array<Money,Money>, Array<Fixnum,Money>
Divide money by money or fixnum and return array containing quotient and modulus.
620 621 622 623 624 625 626 627 628 629 |
# File 'lib/money/money.rb', line 620 def divmod(val) if val.is_a?(Money) a = self.cents b = self.currency == val.currency ? val.cents : val.exchange_to(self.currency).cents q, m = a.divmod(b) return [q, Money.new(m, self.currency)] else return [self.div(val), Money.new(self.cents.modulo(val), self.currency)] end end |
#dollars ⇒ Float
Returns the value of the money in dollars, instead of in cents.
409 410 411 |
# File 'lib/money/money.rb', line 409 def dollars to_f end |
#eql?(other_money) ⇒ Money
Synonymous with #==.
462 463 464 |
# File 'lib/money/money.rb', line 462 def eql?(other_money) self == other_money end |
#exchange_to(other_currency) ⇒ Money
Receive the amount of this money object in another Currency.
957 958 959 960 |
# File 'lib/money/money.rb', line 957 def exchange_to(other_currency) other_currency = Currency.wrap(other_currency) @bank.exchange_with(self, other_currency) end |
#format(*rules) ⇒ String
Creates a formatted price string according to several rules.
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 |
# File 'lib/money/money.rb', line 844 def format(*rules) # support for old format parameters rules = normalize_formatting_rules(rules) if cents == 0 if rules[:display_free].respond_to?(:to_str) return rules[:display_free] elsif rules[:display_free] return "free" end end symbol_value = if rules.has_key?(:symbol) if rules[:symbol] === true symbol elsif rules[:symbol] rules[:symbol] else "" end elsif rules[:html] currency.html_entity else symbol end formatted = case rules[:no_cents] when true "#{self.to_s.to_i}" else "#{self.to_s}" end symbol_position = if rules.has_key?(:symbol_position) rules[:symbol_position] elsif currency.symbol_first? :before else :after end if symbol_value && !symbol_value.empty? formatted = (symbol_position == :before ? "#{symbol_value}#{formatted}" : "#{formatted} #{symbol_value}") end if rules.has_key?(:decimal_mark) and rules[:decimal_mark] and rules[:decimal_mark] != decimal_mark formatted.sub!(decimal_mark, rules[:decimal_mark]) end thousands_separator_value = thousands_separator # Determine thousands_separator if rules.has_key?(:thousands_separator) if rules[:thousands_separator] === false or rules[:thousands_separator].nil? thousands_separator_value = "" elsif rules[:thousands_separator] thousands_separator_value = rules[:thousands_separator] end end # Apply thousands_separator formatted.gsub!(/(\d)(?=(?:\d{3})+(?:[^\d]|$))/, "\\1#{thousands_separator_value}") if rules[:with_currency] formatted << " " formatted << '<span class="currency">' if rules[:html] formatted << currency.to_s formatted << '</span>' if rules[:html] end formatted end |
#hash ⇒ Fixnum
Returns a Fixnum hash value based on the cents
and currency
attributes in order to use functions like & (intersection), group_by, etc.
473 474 475 |
# File 'lib/money/money.rb', line 473 def hash [cents.hash, currency.hash].hash end |
#inspect ⇒ String
Common inspect function
1008 1009 1010 |
# File 'lib/money/money.rb', line 1008 def inspect "#<Money cents:#{cents} currency:#{currency}>" end |
#modulo(val) ⇒ Money
Equivalent to self.divmod(val)
640 641 642 |
# File 'lib/money/money.rb', line 640 def modulo(val) self.divmod(val)[1] end |
#nonzero? ⇒ Money?
Test if the money amount is non-zero. Returns this money object if it is non-zero, or nil otherwise, like Numeric#nonzero?.
704 705 706 |
# File 'lib/money/money.rb', line 704 def nonzero? cents != 0 ? self : nil end |
#remainder(val) ⇒ Money
If different signs self.modulo(val) - val otherwise self.modulo(val)
663 664 665 666 667 668 669 670 671 672 673 |
# File 'lib/money/money.rb', line 663 def remainder(val) a, b = self, val b = b.exchange_to(a.currency) if b.is_a?(Money) and a.currency != b.currency a_sign, b_sign = :pos, :pos a_sign = :neg if a.cents < 0 b_sign = :neg if (b.is_a?(Money) and b.cents < 0) or (b < 0) return a.modulo(b) if a_sign == b_sign a.modulo(b) - (b.is_a?(Money) ? b : Money.new(b, a.currency)) end |
#split(num) ⇒ Array<Money, Money, Money>
Split money amongst parties evenly without loosing pennies.
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 |
# File 'lib/money/money.rb', line 1049 def split(num) raise ArgumentError, "need at least one party" if num < 1 low = Money.new(cents / num) high = Money.new(low.cents + 1) remainder = cents % num result = [] num.times do |index| result[index] = index < remainder ? high : low end return result end |
#symbol ⇒ String
Uses Currency#symbol. If nil
is returned, defaults to “¤”.
714 715 716 |
# File 'lib/money/money.rb', line 714 def symbol currency.symbol || "¤" end |
#thousands_separator ⇒ Object Also known as: delimiter
727 728 729 |
# File 'lib/money/money.rb', line 727 def thousands_separator I18n.t(:"number.format.thousands_separator", :default => currency.thousands_separator || ",") end |
#to_f ⇒ Float
Return the amount of money as a float. Floating points cannot guarantee precision. Therefore, this function should only be used when you no longer need to represent currency or working with another system that requires decimals.
944 945 946 |
# File 'lib/money/money.rb', line 944 def to_f (BigDecimal.new(cents.to_s) / currency.subunit_to_unit).to_f end |
#to_money ⇒ self
Conversation to self
.
1001 1002 1003 |
# File 'lib/money/money.rb', line 1001 def to_money self end |
#to_s ⇒ String
Returns the amount of money as a string.
924 925 926 927 928 929 930 931 932 933 |
# File 'lib/money/money.rb', line 924 def to_s unit, subunit = cents.abs.divmod(currency.subunit_to_unit).map{|o| o.to_s} if currency.decimal_places == 0 return "-#{unit}" if cents < 0 return unit end subunit = (("0" * currency.decimal_places) + subunit)[(-1*currency.decimal_places)..-1] return "-#{unit}#{decimal_mark}#{subunit}" if cents < 0 "#{unit}#{decimal_mark}#{subunit}" end |
#zero? ⇒ Boolean
Test if the money amount is zero.
692 693 694 |
# File 'lib/money/money.rb', line 692 def zero? cents == 0 end |