ruby - Understanding coercion -


I submitted one, which modifies the matrix class so that the joints are real The number can be:

matrix [[25, 93], [-1, 66]] + 5

matrix The class is a way of + () , which is said in this case.

I would also like you to be able to change the order of operation

5 + matrix [[25, 93], [-1, 66]] < / Code>

Matrix seems to support this command of operation * () method and I call it + () method is unsure of how to implement

force course Method is controlled. This method is to return two elements, for which the operator / method has to retry. matrix defines shutdown as:

  def corse (other) case when other numerical return Scalar.new (other), self Increase TypeError, "# {Self.class}" can not be terminated at the end  

Note that this order of operands is not changing , But converts them to a scaler in the numeric value in the class. Therefore, Ruby will see 5 + matrix [...] Scalar.new (5) + matrix [...] .

The scaler class is defined in the same file and it defines its own set operators, which include + and ' Are included. So what you need to do is get rid of line Scalar.Raise ErrOperationNotDefined, "@", @ value.class, other.class and apply your code here, for example other + With Self


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -