Class: Numeric

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

Overview

Open Numeric to add new method.

Instance Method Summary collapse

Instance Method Details

#to_money(currency = nil) ⇒ Money

Converts this numeric into a Money object in the given currency.

Examples:

100.to_money                   #=> #<Money @fractional=10000>
100.37.to_money                #=> #<Money @fractional=10037>
BigDecimal.new('100').to_money #=> #<Money @fractional=10000>

Parameters:

  • currency (Currency, String, Symbol) (defaults to: nil)

    The currency to set the resulting Money object to.

Returns:

See Also:

  • Money.from_numeric


18
19
20
# File 'lib/money/core_extensions.rb', line 18

def to_money(currency = nil)
  Money.from_numeric(self, currency || Money.default_currency)
end