From: hubert@... (Hubert Hung-Hsien Chang) Date: 2002-03-24T12:57:04+09:00 Subject: Re: matrix.rb and question dervied from looking at it. Well... of course we can... silly, i should have just tested myself. def *(m) if(m.is_a?(Array)) #do thing, else super(m) end end Embarassing.... :-) hubert@cs.nyu.edu (Hubert Hung-Hsien Chang) wrote in message news:<98ba0902.0203161224.3682ad98@posting.google.com>... > I took a look at the matrix.rb and here is one question: > > Could we 'add' new way of responding to parameters for > existing method? > > For example, could we add ( or why can't we do this?) > > > def *(m) > if(m.is_a?(Array)) > return m.collect {|x| x * m} > else > return #whatever the original method does. > end > end > > Under the Integer ( or other 'number' class, Fixnum, Bignum and so on.) > class method? > > Is there a way to do it ( without inventing new class)? > > I look at the matrix.rb and they didn't implement this. In other words, > if ou want to multiple the vector by a scalar, do it the '.scalar' way > (or something like that.) > > > Thanks > > > Hubert