Path: lib/currency.rb
Last Update: Thu May 03 11:05:27 -0500 2007
Comparable Money Base UndefinedExchange MissingCurrency RateSourceError UnavailableRates InvalidRate UnknownCurrency Generic SubclassResponsibility InvalidMoneyValue InvalidMoneyString InvalidReentrancy Unimplemented UnknownRate IncompatibleCurrency InvalidCurrencyCode ::Exception Parser Config Factory Currency Formatter Rate TimeQuantitizer ClassMethods Macro Exchange ClassMethods ActiveRecord Exception Currency dot/f_6.png

Copyright (C) 2006-2007 Kurt Stephens <ruby-currency(at)>

See LICENSE.txt for details.


The Currency package provides an object-oriented model of:

  • currencies
  • exchanges
  • exchange rates
  • exchange rate sources
  • monetary values

The core classes are:

The example below uses Currency::Exchange::Xe to automatically get exchange rates from :

   require 'currency'
   require 'currency/exchange/rate/deriver'
   require 'currency/exchange/rate/source/xe'
   require 'currency/exchange/rate/source/timed_cache'

   # Rate source initialization
   provider =
   deriver  = => provider)
   cache = => deriver)
   Currency::Exchange::Rate::Source.default = cache

   usd = Currency::Money('6.78', :USD)
   puts "usd = #{usd.format}"
   cad = usd.convert(:CAD)
   puts "cad = #{cad.format}"

ActiveRecord Suppport

This package also contains ActiveRecord support for money values:

   require 'currency'
   require 'currency/active_record'

   class Entry < ActiveRecord::Base
      money :amount

In the example above, the entries.amount database column is an INTEGER that represents US cents. The currency code of the money value can be stored in an additional database column or a default currency can be used.

Recent Enhancements

Storage and retrival of historical exchange rates

Automatic derivation of rates from base rates.

Rate caching

Rate Providers

Customizable formatting and parsing

Future Enhancements

  • Support for inflationary rates within a currency, e.g. $10 USD in the year 1955 converted to 2006 USD.

SVN Repo

   svn checkout svn://


See the examples/ and test/ directorys


Kurt Stephens



Copyright (C) 2006-2007 Kurt Stephens <ruby-currency(at)>

See LICENSE.txt for details.

Required files

currency/currency_version   currency/config   currency/exception   currency/money   currency/currency   currency/currency/factory   currency/money   currency/formatter   currency/parser   currency/exchange   currency/exchange/rate   currency/exchange/rate/deriver   currency/exchange/rate/source   currency/exchange/rate/source/test   currency/exchange/time_quantitizer   currency/core_extensions