1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Support existence usecase for the custom exception classes

This commit is contained in:
Hiroshi SHIBATA 2019-11-29 17:11:11 +09:00 committed by SHIBATA Hiroshi
parent 5044260dcd
commit c1059e99d3
Notes: git 2019-11-30 08:01:07 +09:00

View file

@ -16,8 +16,14 @@ require_relative "matrix/version"
module ExceptionForMatrix # :nodoc:
class ErrDimensionMismatch < StandardError
def initialize
super("\#{self.name} dimension mismatch")
def initialize(val = nil)
if val.nil?
super
elsif val.is_a?(String)
super(val)
else
super("#{val.class.name} dimension mismatch")
end
end
end
@ -29,7 +35,11 @@ module ExceptionForMatrix # :nodoc:
class ErrOperationNotDefined < StandardError
def initialize(vals)
super("Operation(#{vals[0]}) can\\'t be defined: #{vals[1]} op #{vals[2]}")
if vals.is_a?(Array)
super("Operation(#{vals[0]}) can\\'t be defined: #{vals[1]} op #{vals[2]}")
else
super(vals)
end
end
end