class AnswerValidatable include ActiveModel::Validations attr_accessor :answer attr_accessor :question validates :answer, answer_format: true MockQuestion = Struct.new(:input_type) def initialize input_type @input_type = input_type end def question MockQuestion.new(@input_type) end end