Accessing owner object within composed_of block

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs