def matches?(instance)
      self.instance = instance
      # assign invalid value to each field
      fields.each { |field| instance.send("#{field}=", invalid_value) }
      # sanitize the object calling the method
      instance.send(sanitizer) rescue nil
      # check expectation on results
      fields.all? { |field| valid_value == instance.send(field) }
    end
def matches?(instance)
      self.instance = instance
      # assign invalid value to each field
      fields.each { |field| instance.send("#{field}=", invalid_value) }
      # sanitize the object calling the method
      instance.send(sanitizer) rescue nil
      # check expectation on results
      fields.all? { |field| valid_value == instance.send(field) }
    end
Actual match code