class Ecu class ValueComparison def initialize(left, right) # check_compatibility(left, right) @left, @right = left, right end def eql? case [@left, @right] in [NilClass, NilClass] then @left == @right in [String, String] then @left == @right in [Numeric, Numeric] then @left == @right in [Array, Array] then arrays_eql?(@left, @right) in [_, _] then false end end private def arrays_eql?(left, right) return false unless left.size == right.size left.zip(right).all? { self.class.new(*_1).eql? } end def check_compatibility(left, right) if left.class != right.class fail ArgumentError, "Values must have the same class for comparison (#{left}: #{left.class}/#{right}: #{right.class})" end end end end