title: How to manipulate collection without hitting the database?
body: <p>In my Rails application I have this little helper method that takes a collection as a parameter:</p>
  
  <pre><code>def calculate_column_width(collection)
    if collection.where(:sample =&gt; true).present?
      "10%"
    else
      "20%"
    end
  end
  </code></pre>
  
  <p>It works but I don't like the fact that it creates two additional database queries.</p>
  
  <p>How can I rewrite the function so it runs on the collection (e.g. <code>@people</code>) which has already been loaded into memory by Rails?</p>
  
  <p>Thanks for any help.</p>