DRY: need some help with blocks

Hi all

I have the following method in a model:

def validate
if !@errors.on(:abbrevation)
@errors.add(:abbrevation,
self.class.error_messages[:not_allowed_chars_in_abbrevation]) unless
abbrevation =~ /^[A-Z]+$/
end
if !@errors.on(:abbrevation)
@errors.add(:abbrevation,
self.class.error_messages[:abbrevation_has_wrong_length]) unless
abbrevation.length == 2
end
end

I repeat if !@errors.on(:abbrevation) 2 times and maybe will have to
repeat it again in future when adding more validations.

I’d really like to shorten this code, some sort of loop that runs as
long as there is no error and in every loop another validation block is
executed:

while !@errors.on(:abbrevation) do

do some validation, and another validation, and another…

end

I guess I will have to use lambda or so, but I’m quite unsure how to use
it appropriately in this case. Anyone has an idea? :slight_smile:

Thanks
Josh