From: Benoit Daloze Date: 2010-05-13T22:07:18+09:00 Subject: Re: In Ruby, can the coerce() method know what operator it is th Hi, 2010/5/13 Colin Bartlett : > (B) The actual code in Matrix::Scalar#+ raises an exception for > Numeric + (Matrix or Vector), > > but also allows for (Numeric or > Matrix::Scalar) + Matrix::Scalar, with in both cases the result being > Matrix::Scalar, and I can't immediately think of any circumstances > where those cases would actually arise. I first thought this would be for performance reason, to coerce once instead of 2 times, but I don't see any use case except: (Matrix::Scalar.new(4) + 3) * matrix which should never be done, as Matrix::Scalar is supposed to be a private class: # Private CLASS class Scalar < Numeric # :nodoc: Maybe Marc-André (the new maintainer) could give us a hint if he sees this thread. Personally, I used a simple Scalar class like in Matrix, but I just define the * and / operator. Then if you do Numeric + Matrix, you get: NoMethodError: undefined method `+' for # Which is almost self-explanatory I think. Regards, B.D.