# Accessing owner object within composed\_of block

**URL:** <https://www.ruby-forum.com/t/accessing-owner-object-within-composed-of-block/142430>\
**Category:** Rails\
**Created:** [July 7, 2008, 10:39pm UTC](https://www.ruby-forum.com/t/accessing-owner-object-within-composed-of-block/142430 "2008-07-07T22:39:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_LIn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/45deac/32.png) [@Eric\_LIn](https://www.ruby-forum.com/u/Eric_LIn)\
**Post date:** [July 7, 2008, 10:39pm UTC](https://www.ruby-forum.com/t/accessing-owner-object-within-composed-of-block/142430/1 "2008-07-07T22:39:10Z")

</div>

Hi All,

In my Account model I have a composed\_of declaration like this:

class Account  
composed\_of :balance, … do |value|  
Money.new(value, ‘USD’)  
end  
end

I would like to modify this so instead of always creating a USD, the  
currency can be inferred from the ‘currency’ field in account. That  
is,

class Account  
composed\_of :balance, … do |value|  
Money.new(value, currency)  
end  
end

Of course, this wouldn’t work since Account#currency is not within the  
block’s scope. Is there anyway for me to access Account#currency  
within the composed\_of block? Something akin to has\_many’s  
proxy\_owner object.

Thanks,  
Eric
