class Ecu class ValueComparison def initialize(left, right) # check_compatibility(left, right) @left, @right = left, right end def eql? return false unless @left.class == @right.class case @left when NilClass then @left == @right when String then @left == @right when Numeric then @left == @right when Array then arrays_eql?(@left, @right) else fail "Unkown value class: #{@left.class}" 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