I think your whole approach is a bit odd in the Ruby context. A more Rubyish and Railsy approach would be to write a macro and then use a block in your subclasses rather than a private method.
Something like this:
class Validator < ActiveModel::EachValidator
def self.validate_using(&block)
define_method :validate_each do |record, attribute, value|
unless block[value]
record.errors.add(attribute, attribute.to_sym, options.merge(value: value))
end
end
end
end
class KppValidator < Validator
validate_using { |kpp| kpp.size == 9 }
end
Since this defines the whole validate_each
method, this even saves you a method call during validation (at the minor expense of a bit of extra work while initializing everything).
I don't know if this is worthwhile for just ten validators, I'll leave that up to you.