title: What is the right way to override a setter method in Ruby on Rails?
body: <p>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.</p>
  
  <pre><code>attr_accessible :attribute_name
  
  def attribute_name=(value)
    ... # Some custom operation.
  
    self[:attribute_name] = value
  end
  </code></pre>
  
  <p>The above code seems to work as expected. However, <em>I would like to know if, by using the above code, in future I will have problems or, at least, what problems "should I expect"/"could happen" with Ruby on Rails</em>. If that isn't the right way to override a setter method, what is the right way?</p>
  
  <hr>
  
  <p><em>Note</em>: If I use the code</p>
  
  <pre><code>attr_accessible :attribute_name
  
  def attribute_name=(value)
    ... # Some custom operation.
  
    self.attribute_name = value
  end
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>SystemStackError (stack level too deep):
    actionpack (3.2.2) lib/action_dispatch/middleware/reloader.rb:70
  </code></pre>