From: Robert Klemme Date: 2008-02-10T02:30:00+09:00 Subject: Re: Inheriting from / Delegating to Integer - Currency class implementation On 09.02.2008 15:25, Pascal Ehlert wrote: > On 2/9/2008 Rick DeNatale wrote: >> def coerce(other) >> [self, other.to_currency] >> end > > Whoa, that looks really interesting. > Thanks a lot, Rick! > > However, is there another way to implement the Currency class using > DelegateClass? There might be but you will have to handle type differences anyway. You will have to implement #coerce, #+ etc. in any case. I recommend to use Rick's approach because it is much cleaner. > It still feels wrong to me to write +, -, * and / on my own, although > they are exactly the same as in the Integer class. Actually, they are not the same. Adding currencies is significantly more complex than adding ints. What happens if you add 5 EUR and 12 USD? All sorts of issues are lurking here. A currency value is (at least) a decimal value and a currency identifier - at least this is the most straightforward definition I can think of. You are doing yourself a favor by doing it properly - it's not that difficult. Kind regards robert