title: Overwrite has_many getter
body: <p>I have the following model:</p>
  
  <pre><code>class Metric &lt; ApplicationRecord
    has_many key_phrases
  end
  </code></pre>
  
  <p>And I want to create a method that overwrites the getter <code>key_phrases</code>, something like:</p>
  
  <pre><code>class Metric &lt; ApplicationRecord
    has_many key_phrases
  
    def key_phrases
      # if current value is not an empty array, return, otherwise creates, something like:
      current_value = super()
      return current_value unless current_value.nil?
  
      get_key_phrases.each do |k|
        key_phrases.create(k)
      end
      return key_phrases
    end
  end
  </code></pre>
  
  <p>I know what I want to do, but because I lack knowledge about Ruby and Rails, I don't know exactly how to code that. </p>