我有一个模块,我在其中定义了这样的函数:
module A
def item=(item)
...
end
end
然后我有一个具有belongs_to关联的类,并包含模块A:
class User < ActiveRecord::Base
include A
belongs_to :item
...
end
我希望User类拥有我的item =,但似乎这种方式不起作用。
有谁能告诉我如何覆盖默认的item =方法?
答案 0 :(得分:1)
在include A
:
belongs_to :item
语句
class User < ActiveRecord::Base
belongs_to :item
include A
...
end
belongs_to :item
语句正在重新定义item=
方法。