title: Calculation method for model with different has_many associations
body: <p>I wrote a method that calculations a certain value for a business case.</p>
  
  <p>My models look like this</p>
  
  <pre><code>class CEntry &lt; ActiveRecord::Base
      belongs_to :bcase
  end
  
  class SEntry &lt; ActiveRecord::Base
      belongs_to :bcase
  end
  
  class CnqEntry &lt; ActiveRecord::Base
      belongs_to :bcase
  end
  
  class Bcase &lt; ActiveRecord::Base
           has_many :c_entries, :dependent =&gt; :destroy
      has_many :s_entries, :dependent =&gt; :destroy
      has_many :cnq_entries, :dependent =&gt; :destroy
  
  end
  </code></pre>
  
  <p>Now I wrote this method for the business case model</p>
  
  <pre><code>def int_rc
      x = 0
      self.c_entries.where(:hours != 0 &amp;&amp; :order_no !=).each do |entry|
          x = x + (entry.hours * entry.rate.ratevalue)
      end
      return x.round(2)
  end
  </code></pre>
  
  <p>But I need this for c_entries, s_entries and cnq_entries and I guess it would be stupid to write it 3 times because it would be 90% the same.</p>
  
  <p>So what I try is set it variable and fill it with the right object type. Thats what I have and is not working:</p>
  
  <pre><code>def int_rc(type)
      x = 0
      self.type.where(:hours != 0 &amp;&amp; :order_no !=).each do |entry|
          x = x + (entry.hours * entry.rate.ratevalue)
      end
      return x.round(2)
  end
  </code></pre>
  
  <p>And then I would call <code>@bcase.int_rc(c_entries)</code>.</p>
  
  <p>What do you think?</p>