Class: ActsAsMoney::Money
- Inherits:
-
BigDecimal
- Object
- BigDecimal
- ActsAsMoney::Money
- Defined in:
- lib/acts_as_money/money.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#decimals ⇒ Object
readonly
Returns the value of attribute decimals.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(amount, decimals = 2) ⇒ Money
constructor
A new instance of Money.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(amount, decimals = 2) ⇒ Money
Returns a new instance of Money.
7 8 9 10 11 12 |
# File 'lib/acts_as_money/money.rb', line 7 def initialize amount, decimals = 2 @decimals = decimals amount = 0 unless amount @amount = BigDecimal.new(amount.to_s).round(@decimals) super @amount end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
5 6 7 |
# File 'lib/acts_as_money/money.rb', line 5 def amount @amount end |
#decimals ⇒ Object (readonly)
Returns the value of attribute decimals.
5 6 7 |
# File 'lib/acts_as_money/money.rb', line 5 def decimals @decimals end |
Instance Method Details
#eql?(other) ⇒ Boolean
27 28 29 |
# File 'lib/acts_as_money/money.rb', line 27 def eql? other @amount == other.amount end |
#hash ⇒ Object
23 24 25 |
# File 'lib/acts_as_money/money.rb', line 23 def hash @amount.hash end |
#inspect ⇒ Object
35 36 37 |
# File 'lib/acts_as_money/money.rb', line 35 def inspect to_s end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/acts_as_money/money.rb', line 31 def to_s ActiveSupport::NumberHelper.number_to_currency to_d end |