Sometimes you need to prevent code from executing recursively. I had to do this recently in order to prevent an infinite recursion in ActiveRecord callbacks. A before-save hook needed to save a parent model attribute, which because of an :autosave option would then try to save the child model, which would then try to save the parent… and so on until the stack overflowed.
I tried to use this code to prevent recursion with a validate method in a model. It didn’t prevent. Is there anything unique to the validate method that would prevent the prevent from working?