From: Jason Roelofs Date: 2008-04-01T03:24:46+09:00 Subject: Re: Modifying FIX::* method The proper way is to implement and enforce "y * 2". Is there any specific reason you want people to be able to do "2 * y" ? Jason On Mon, Mar 31, 2008 at 1:58 PM, Alex DeCaria wrote: > I have a class such as > > Class Foo > def initialize(x) > @x = x > end > attr_read :x > end > > 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. For example: > > y = Foo.new(3) > z = 2*y > print z.x => 6 > > or > > z = 2.0*y > print z.x => 6.0 > > 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. > > I know I can put a "*" method in my Foo class, and get it to do things > like "y*2", but how do I get "2*y"? > > Thanks in advance. > -- > Posted via http://www.ruby-forum.com/. > >