I've been thinking about this for a while! It exists in ActiveSupport already: https://github.com/rails/rails/issues/20339