Class: Money::Bank::SingleCurrency

Inherits:
Base
  • Object
show all
Defined in:
lib/money/bank/single_currency.rb

Overview

Class to ensure client code is operating in a single currency by raising if an exchange attempts to happen.

This is useful when an application uses multiple currencies but it usually deals with only one currency at a time so any arithmetic where exchanges happen are erroneous. Using this as the default bank means that that these mistakes don’t silently do the wrong thing.

Instance Attribute Summary

Attributes inherited from Base

#rounding_method

Instance Method Summary collapse

Methods inherited from Base

#initialize, instance, #same_currency?, #setup

Constructor Details

This class inherits a constructor from Money::Bank::Base

Instance Method Details

#exchange_with(from, to_currency, &block) ⇒ Object

Raises a DifferentCurrencyError to remove possibility of accidentally exchanging currencies



19
20
21
# File 'lib/money/bank/single_currency.rb', line 19

def exchange_with(from, to_currency, &block)
  raise DifferentCurrencyError, "No exchanging of currencies allowed: #{from} #{from.currency} to #{to_currency}"
end