Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't really know if I understood your question correctly, but I'll post my answer anyway.</p> <p>I would make a function:</p> <pre><code>def simplified_conditions conds, prms, perform_and_on_hashes = false conds.each do |h| h.each do |method_name, symbols_array| symbols_array.each do |symb| return false unless prms[symb].send method_name end end return true unless perform_and_on_hashes end return true end </code></pre> <p>And pass it a conditions structure that looks like so:</p> <pre><code>[ { 'boolean_function_name' =&gt; [:array,:of,:symbols], 'another_function_name' =&gt; [:array,:of,:symbols], 'another_function_name' =&gt; [:array,:of,:symbols] }, { 'boolean_function_name' =&gt; [:array,:of,:symbols], 'another_function_name' =&gt; [:array,:of,:symbols], 'another_function_name' =&gt; [:array,:of,:symbols] }, { 'boolean_function_name' =&gt; [:array,:of,:symbols], 'another_function_name' =&gt; [:array,:of,:symbols], 'another_function_name' =&gt; [:array,:of,:symbols] } ] </code></pre> <p>So in your sample conditions, the array will look like:</p> <pre><code>conds = [ { 'present?' =&gt; [:a], 'nil?' =&gt; [:b] }, { 'present?' =&gt; [:a], 'nil?' =&gt; [:c] }, { 'present?' =&gt; [:a], 'nil?' =&gt; [:e] }, { 'present?' =&gt; [:b], 'nil?' =&gt; [:c] }, { 'present?' =&gt; [:b], 'nil?' =&gt; [:d] } ] # And then to call it: final_boolean_result = simplified_conditions(conds, params, false) </code></pre> <p>This will return true if any of the lines in your example is true. I you want ALL of them to be true, simply change the last parameter to <code>true</code>.</p> <p>If I misunderstood your question, please leave a comment.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload