Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>see here</p> <pre><code>2 and 7 #=&gt; 7 2 or 7 #=&gt; 2 2 or 7 and 12 #=&gt; 12 2 or 7 or 12 #=&gt; 2 2 or 7 and 12 or 10 #=&gt; 12 true and true and false #=&gt; false true or true or false #=&gt; true true and true or false #=&gt; true true or true and false #=&gt; false true or true and false and true #=&gt; false </code></pre> <p><em><strong>Summary :</em></strong></p> <p>(a) when you will use in an expression with only <code>and</code> operator value of the expression is always the last operand and the reverse is true for expression having only <code>or</code> operator.In case of Boolean the full expression will be evaluated.</p> <p>(b) When an expression will have <code>and</code> and <code>or</code> mixed, evaluation will continue till the last <code>and</code> and its <strong><code>ROH</code></strong> operand will be the value of the expression(in case of <code>Boolean</code> last <code>and</code> RHO,LHO will be evaluated,after that result will be produced as Boolean operation rule.</p> <p><em>Applying the rule of (b)</em></p> <p>below code works:</p> <pre><code>if true or true and false then puts "Quux" end #=&gt; nil a = true or true and false #=&gt; false if a then puts "Foo" end #Foo #=&gt; nil </code></pre> <p>Below code outputs <code>Foo</code> due to the precedence of <code>=</code> over <code>and</code>,<code>or</code>.</p> <p>The expression <code>a = true or true and false</code> evaluates as follows applying the rule (b)</p> <pre><code>a = true or true and false || (a = true) or true and false || true and false || false </code></pre> <p><em>One more good application of rule (b)</em></p> <pre><code>if 2 and 3 or nil p "hi" end #=&gt; "hi" if 2 or 3 and nil p "hello" end #nothing printed </code></pre>
    singulars
    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.
    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