I am reading the money gem source code and I can't seem to understand the constructor:
def initialize(obj, currency = Money.default_currency, bank = Money.default_bank)
@fractional = obj.respond_to?(:fractional) ? obj.fractional : as_d(obj)
@currency = obj.respond_to?(:currency) ? obj.currency : Currency.wrap(currency)
@currency ||= Money.default_currency
@bank = obj.respond_to?(:bank) ? obj.bank : bank
end
Why are we testing if obj
has a "fractional"
method? When does that return true and when does it return false? Same questions for currency in the next line.
Thanks