What is the right way to override a setter method in Ruby on Rails?

前端 未结 5 835
春和景丽
春和景丽 2020-11-28 18:05

I am using Ruby on Rails 3.2.2 and I would like to know if the following is a \"proper\"/\"correct\"/\"sure\" way to override a setter method for a my class attribute.

5条回答
  •  情深已故
    2020-11-28 19:03

    Using attr_writer to overwrite setter attr_writer :attribute_name

      def attribute_name=(value)
        # manipulate value
        # then send result to the default setter
        super(result)
      end
    

提交回复
热议问题