TIL - Rails XOR validation

I learned how to do XOR validation

Talk is cheap, show me the code

class SomeClass
  include ActiveModel::Validations

  validate :a_or_b?

  private

  def a_or_b?
    return if a.blank? ^ b.blank?
    errors.add(
      :base,
      :a_or_b_required,
      message: 'either a or b must be present, but not both'
    )
  end
end