I have a class in my model written inside a vendor's code(which I cannot modify) which has a Proc
attached to it. Considering an example for a shirt class, the code looks like the one below.
class Shirt < ActiveRecord::Base
before_validation -> { self.size ||= 'medium' }
# Some code here
end
(Note that this piece of code is setting the default shirt size)
Say,I now need to change the default shirt size to large in a decorator class. The code would look something like
Shirt.class_eval do
before_validation -> { self.size ||= 'large' }
# Some more code
end
However, the default shirt size is still set to medium
since the before_validation
callback in the original class is still called.
Is there a elegant way to remove the callback in the original code and use the class_eval validation instead?