From: Shawn Anderson Date: 2008-04-01T03:35:08+09:00 Subject: Re: Modifying FIX::* method ------=_Part_14711_31447217.1206988500926 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Adam, I believe the OP wanted a Foo object returned, not a Fixnum. /Shawn On Mon, Mar 31, 2008 at 11:27 AM, Adam Shelly wrote: > On 3/31/08, Alex DeCaria wrote: > > I want to be able to multiply a NUMERIC object by my Foo object and have > > it return a new Foo object with all the instance variables multiplied by > > the Numeric object. > [...] > > I'm thinking I have to modify the "*" method for all the subclasses of > > the NUMERIC class. Is this correct? Or am I missing something. > > > > You don't need to modify Numeric, you just need to tell it how to > coerce your object into a number. > > irb(main):057:0* class Foo > irb(main):058:1> def initialize(x) > irb(main):059:2> @x=x > irb(main):060:2> end > irb(main):061:1> def coerce(n) > irb(main):062:2> [n,@x] > irb(main):063:2> end > irb(main):064:1> end > => nil > irb(main):065:0> 2 + Foo.new(3) > => 5 > irb(main):066:0> f=Foo.new(4) > => # > irb(main):067:0> 8/f > => 2 > > -Adam > > ------=_Part_14711_31447217.1206988500926--