Class: ActsAsMoney::Money

Inherits:
BigDecimal
  • Object
show all
Defined in:
lib/acts_as_money/money.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#amountObject (readonly)

Returns the value of attribute amount.



5
6
7
# File 'lib/acts_as_money/money.rb', line 5

def amount
  @amount
end

#decimalsObject (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

Returns:

  • (Boolean)


27
28
29
# File 'lib/acts_as_money/money.rb', line 27

def eql? other
  @amount == other.amount
end

#hashObject



23
24
25
# File 'lib/acts_as_money/money.rb', line 23

def hash
  @amount.hash
end

#inspectObject



35
36
37
# File 'lib/acts_as_money/money.rb', line 35

def inspect
  to_s
end

#to_sObject



31
32
33
# File 'lib/acts_as_money/money.rb', line 31

def to_s
  ActiveSupport::NumberHelper.number_to_currency to_d
end