Ruby/RoR: calling original method via super()?

后端 未结 3 1268

In a RoR app, I want to specialize ActiveRecord\'s update_attributes() method in one of my models, extracting some of the attributes for special handling and passing the res

3条回答
  •  臣服心动
    2020-12-30 06:11

    This looks like a better use for alias_method_chain:

    def update_attributes_with_special(attrs)
      attrs.each_pair do |key, val|
        unless has_attribute?(key)
          do_special_processing(key, val)
          attrs.delete(key)
        end
      end
      update_attributes_without_special(attrs)
    end
    alias_method_chain :update_attributes, :special
    

提交回复
热议问题