Method: Money.new_with_amount

Defined in:
lib/money/money.rb

.new_with_amount(amount, currency = Money.default_currency, bank = Money.default_bank) ⇒ Money

Creates a new Money object of amount value , with given currency.

The amount value is expressed in the main monetary unit, opposite to the subunit-based representation used internally by this library called cents.

Examples:

Money.new_with_amount(100)
#=> #<Money @fractional=10000 @currency="USD">
Money.new_with_amount(100, "USD")
#=> #<Money @fractional=10000 @currency="USD">
Money.new_with_amount(100, "EUR")
#=> #<Money @fractional=10000 @currency="EUR">

Parameters:

  • amount (Numeric)

    The money amount, in main monetary unit.

  • currency (Currency, String, Symbol) (defaults to: Money.default_currency)

    The currency format.

  • bank (Money::Bank::*) (defaults to: Money.default_bank)

    The exchange bank to use.

Returns:

See Also:

  • new


189
190
191
192
193
194
# File 'lib/money/money.rb', line 189

def self.new_with_amount(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