title: Rails apply boolean method to filter query results
body: <p>I have some complicated boolean methods that I want to use as a filter for Database query results. I want a solution that would work for both SQL and Mongoid DB.</p>
  
  <pre><code>class Bar &lt; ActiveRecord::Base OR include Mongoid::Document
  
      [field :some_field]
  
      def method1?
      ...
      end
  
      def method1?
      ...
  end
  </code></pre>
  
  <p>This is what I would like to write :</p>
  
  <pre><code>def self.someFunc
      Bar.where(some_field: some_value).filter(method1?, method2?)
  end
  </code></pre>
  
  <p>Is there a simpler way than do do that :</p>
  
  <pre><code>def self.someFunc
      results = Array.new
      Bar.where(some_field: some_value).each do |result|
         if result.filter1? &amp;&amp; result.filter2?
             results &lt;&lt; result
         end
      end
      results
  end
  </code></pre>