Skip to content

Commit 9b95031

Browse files
committed
raise method accepts 3 argument with exception class
1 parent f47f207 commit 9b95031

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/matrix.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ def initialize
2828
end
2929

3030
class ErrOperationNotDefined < StandardError
31-
def initialize(op, sc, oc)
32-
super("Operation(#{op}) can\\'t be defined: #{sc} op #{oc}")
31+
def initialize(vals)
32+
super("Operation(#{vals[0]}) can\\'t be defined: #{vals[1]} op #{vals[2]}")
3333
end
3434
end
3535

3636
class ErrOperationNotImplemented < StandardError
37-
def initialize(op, sc, oc)
38-
super("Sorry, Operation(#{op}) not implemented: #{sc} op #{oc}")
37+
def initialize(vals)
38+
super("Sorry, Operation(#{vals[0]}) not implemented: #{vals[1]} op #{vals[2]}")
3939
end
4040
end
4141
end
@@ -1066,7 +1066,7 @@ def *(m) # m is matrix or vector or number
10661066
def +(m)
10671067
case m
10681068
when Numeric
1069-
raise ErrOperationNotDefined, "+", self.class, m.class
1069+
raise ErrOperationNotDefined, ["+", self.class, m.class]
10701070
when Vector
10711071
m = self.class.column_vector(m)
10721072
when Matrix
@@ -1093,7 +1093,7 @@ def +(m)
10931093
def -(m)
10941094
case m
10951095
when Numeric
1096-
raise ErrOperationNotDefined, "-", self.class, m.class
1096+
raise ErrOperationNotDefined, ["-", self.class, m.class]
10971097
when Vector
10981098
m = self.class.column_vector(m)
10991099
when Matrix
@@ -1226,7 +1226,7 @@ def **(other)
12261226
v, d, v_inv = eigensystem
12271227
v * self.class.diagonal(*d.each(:diagonal).map{|e| e ** other}) * v_inv
12281228
else
1229-
raise ErrOperationNotDefined, "**", self.class, other.class
1229+
raise ErrOperationNotDefined, ["**", self.class, other.class]
12301230
end
12311231
end
12321232

@@ -2129,7 +2129,7 @@ def *(x)
21292129
when Matrix
21302130
Matrix.column_vector(self) * x
21312131
when Vector
2132-
raise ErrOperationNotDefined, "*", self.class, x.class
2132+
raise ErrOperationNotDefined, ["*", self.class, x.class]
21332133
else
21342134
apply_through_coercion(x, __method__)
21352135
end
@@ -2180,7 +2180,7 @@ def /(x)
21802180
els = @elements.collect{|e| e / x}
21812181
self.class.elements(els, false)
21822182
when Matrix, Vector
2183-
raise ErrOperationNotDefined, "/", self.class, x.class
2183+
raise ErrOperationNotDefined, ["/", self.class, x.class]
21842184
else
21852185
apply_through_coercion(x, __method__)
21862186
end

0 commit comments

Comments
 (0)