I have a module that defines some methods and which I include in some Rails models. I want the models where the module is included to have some specific methods defined (as if I want them to implement an interface).
However the problem arises when the I want the models to have a method that turns out to be an attribute that active record already defined.
My code is like as follows:
Module Mod
included do
# some code...
# require some methods to be implemented by including class
def do_x
raise('not implemented, please override me')
end
def name
raise('not implemented, please override me')
end
end
end
class Supplier < ApplicationRecord
# already has a name attribute
include Mod
# this overrides do_x of mod
def do_x
# some code...
end
end
The name
method of the Supplier class actually get overridden by that of the module Mod, which is not the behavior I want.