# Suggestions for adding a new abstract data type to AR using a composed\_of

**URL:** <https://www.ruby-forum.com/t/suggestions-for-adding-a-new-abstract-data-type-to-ar-using-a-composed-of/139496>\
**Category:** Rails\
**Created:** [June 4, 2008, 1:07pm UTC](https://www.ruby-forum.com/t/suggestions-for-adding-a-new-abstract-data-type-to-ar-using-a-composed-of/139496 "2008-06-04T13:07:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manuel\_Vidaurre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@Manuel\_Vidaurre](https://www.ruby-forum.com/u/Manuel_Vidaurre)\
**Post date:** [June 4, 2008, 1:07pm UTC](https://www.ruby-forum.com/t/suggestions-for-adding-a-new-abstract-data-type-to-ar-using-a-composed-of/139496/1 "2008-06-04T13:07:31Z")

</div>

Hello everybody,

I had been searching the web but I can’t find a way to add a new  
abstract data type to AR using a composed\_of. To put this in context  
let me explain what I want to do:  
In a rails app I had developed a Money Class that use to  
attr :amount, :currency. I had add functionality to have Factories for  
creating Money in different currencies, arithmetical operations,  
comparisons, and several financial calculations (interest, expected  
values, amortized payments, etc.) . I had been using this in my models  
as

composed\_of :price\_money,  
:class\_name =\> Money,  
:mapping =\>  
[ # database ruby  
[:price, :amount],  
[:currency, :currency]  
]

I have also a Bank Class were I kept the exchange rates among  
currencies  
After talking in RailsConf2008 with several railers they told me that  
will be good if I can deploy this as a plugin or a gem. I had been  
working in extracting this as a plugin, but I would like to be able to  
add a new abstract data type to AR for money, then we can use in  
migrations something like this as example:

create\_table “prices”, :force =\> true do |t|  
t.money “price”, :precision =\> 16, :scale =\> 4. :default\_currency  
=\> “USD”  
end

Rather than

create\_table “prices”, :force =\> true do |t|  
t.decimal “price”, :precision =\> 16, :scale =\> 4  
t.string “currency”, :limit =\> 3, :default =\> “USD”, :null =\>  
false  
end

And get out also the need for the composed\_of declaration.

I will appreciate very much any suggestion how to tackle this.

Best regards,

Manuel Vidaurre
