summaryrefslogtreecommitdiff
path: root/lib/matrix.rb
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2019-11-29 17:11:11 +0900
committerSHIBATA Hiroshi <hsbt@ruby-lang.org>2019-11-30 08:00:40 +0900
commitc1059e99d3f74fdd5d9a9792544a9ebc8a10edf7 (patch)
treebafa619581210fc4c1292af04a3f00fb785aec46 /lib/matrix.rb
parent5044260dcd1d1b51f2e217ca519431ab5a1cf8c2 (diff)
Support existence usecase for the custom exception classes
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2699
Diffstat (limited to 'lib/matrix.rb')
-rw-r--r--lib/matrix.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb
index 8c31643eab..b4d1be33bb 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -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