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 String then @left == @right when Numeric then @left == @right when Array then return false unless @left.size == @right.size @left.zip(@right).all? do |a, b| self.class.new(a, b).eql? end when NilClass then @left == @right else fail "Unkown value class: #{@left.class}" end end private 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