我有一个简单的验证类:
class MappingValidator
def validate(mapping)
end
protected
def validate_presence_of_title(mapping)
...
end
def validate_presence_of_key(mapping)
...
end
def validates_class_exists(mapping)
...
end
end
在该validate方法中,我想调用任何以开头并作为参数validate_传递的方法。mapping这也适用于 的子类MappingValidator,因此如果子类声明了一个以validate_它开头的方法,则在子类实例上调用 validate 时也会调用该方法。调用顺序无关紧要。