假设我们有一个名为"Items"的表、一个名为"Name"的列和一个名为"Quantity"的列.
然后假设我们有一个这样的item实例:
@item = Item.first
在此实例中,您可以调用方法,例如:
@item.name.present?
@item.quantity.is_a?(Integer)
如何将我自己的方法添加到所有列,例如,如果我想调用:
@item.name.custom_method?
@item.quantity.custom_method?
@item.name.custom_method_2(:xyz)
@item.quantity.custom_method_2(:xyz)
所以我想给所有的columns属性添加方法,每一个都做一个自定义的事情.我见过一些gem,Rails用dirty做了,比如给columns/attributes添加changed?
.