[前][次][番号順一覧][スレッド一覧]

ruby-changes:58974

From: Hiroshi <ko1@a...>
Date: Sat, 30 Nov 2019 12:49:58 +0900 (JST)
Subject: [ruby-changes:58974] c1059e99d3 (master): Support existence usecase for the custom exception classes

https://git.ruby-lang.org/ruby.git/commit/?id=c1059e99d3

From c1059e99d3f74fdd5d9a9792544a9ebc8a10edf7 Mon Sep 17 00:00:00 2001
From: Hiroshi SHIBATA <hsbt@r...>
Date: Fri, 29 Nov 2019 17:11:11 +0900
Subject: Support existence usecase for the custom exception classes


diff --git a/lib/matrix.rb b/lib/matrix.rb
index 8c31643..b4d1be3 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -16,8 +16,14 @@ require_relative "matrix/version" https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L16
 
 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: https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L35
 
   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
 
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]