English and symbolic boolean operators in Ruby

  • Published on
    03-Jul-2015

  • View
    164

  • Download
    1

Embed Size (px)

DESCRIPTION

learn the difference between the boolean operators and what this has to do with short-circuit evaluation and precedence.

Transcript

<ul><li> 1. and (and&amp;&amp;) (or||) operators @DonSchado | 15.01.2014</li></ul> <p> 2. and (and&amp;&amp;) (or||) operators olic boolean nglish and symb e@DonSchado | 15.01.2014 3. Quiztime!!! o/ 4. foo=true&amp;&amp;"bar" foo=?#=&gt;? 5. foo=true&amp;&amp;"bar" foo="bar"#=&gt;"bar" 6. foo=true&amp;&amp;"bar"#=&gt;"bar"foo="bar"foo=trueand"bar" foo=?#=&gt;? 7. foo=true&amp;&amp;"bar"#=&gt;"bar"foo="bar"foo=trueand"bar" foo=true#=&gt;"bar" 8. foo=42&amp;&amp;foo*2 foo=?#=&gt;? 9. foo=42&amp;&amp;foo*2#=&gt;NoMethodError: undefinedmethod`*'fornil:NilClassfoo=nil 10. foo=42&amp;&amp;foo*2#=&gt;NoMethodError: undefinedmethod`*'fornil:NilClassfoo=nilfoo=42andfoo*2 foo=?#=&gt;? 11. foo=42&amp;&amp;foo*2#=&gt;NoMethodError: undefinedmethod`*'fornil:NilClassfoo=nilfoo=42andfoo*2 foo=42#=&gt;84 12. short-circuit evaluation &amp; precedence 13. short-circuit evaluation (or McCarthy evaluation)... denotes the semantics of some Boolean operators [...] in which the second argument is only executed or evaluated if the rst argument does not sufce to determine the value of the expression. Short-circuit operators are, in effect, control structures rather than simple arithmetic operators http://en.wikipedia.org/wiki/Short-circuit_evaluation 14. short-circuit evaluation (or McCarthy evaluation)... denotes the semantics of some Boolean operators [...] in which the second argument is only executed or evaluated if the rst argument does not sufce to determine the value of the expression. Short-circuit operators are, in effect, control structures rather than simple arithmetic operators http://en.wikipedia.org/wiki/Short-circuit_evaluation:foo&amp;&amp;:bar#=&gt;:bar 15. short-circuit evaluation (or McCarthy evaluation)... denotes the semantics of some Boolean operators [...] in which the second argument is only executed or evaluated if the rst argument does not sufce to determine the value of the expression. Short-circuit operators are, in effect, control structures rather than simple arithmetic operators http://en.wikipedia.org/wiki/Short-circuit_evaluation:foo&amp;&amp;:bar if:foo :bar end#=&gt;:bar 16. short-circuit evaluation (or McCarthy evaluation)... denotes the semantics of some Boolean operators [...] in which the second argument is only executed or evaluated if the rst argument does not sufce to determine the value of the expression. Short-circuit operators are, in effect, control structures rather than simple arithmetic operators http://en.wikipedia.org/wiki/Short-circuit_evaluation:foo&amp;&amp;:bar#=&gt;:barif:foo :bar end:foo||:bar#=&gt;:foo 17. short-circuit evaluation (or McCarthy evaluation)... denotes the semantics of some Boolean operators [...] in which the second argument is only executed or evaluated if the rst argument does not sufce to determine the value of the expression. Short-circuit operators are, in effect, control structures rather than simple arithmetic operators http://en.wikipedia.org/wiki/Short-circuit_evaluation:foo&amp;&amp;:bar#=&gt;:barif:foo :bar end:foo||:bar if:foo :foo else :bar end#=&gt;:foo 18. precedencehigh!, ~, unary + ** unary *, /, % +, &amp; |, ^ &gt;, &gt;=, =, =, =, ready_to_rock?orraise"Notready!" 28. examples raise"Notready!"unlessready_to_rock?=&gt;ready_to_rock?orraise"Notready!"nextifwidget=widgets.pop=&gt;widget=widgets.popandnext 29. examples raise"Notready!"unlessready_to_rock?=&gt;ready_to_rock?orraise"Notready!"nextifwidget=widgets.pop=&gt;widget=widgets.popandnext@post=Post.find_by_name(name)and@post.publish! 30. examples raise"Notready!"unlessready_to_rock?=&gt;ready_to_rock?orraise"Notready!"nextifwidget=widgets.pop=&gt;widget=widgets.popandnext@post=Post.find_by_name(name)and@post.publish!foo=get_fooorraise"Couldnotfindfoo!" 31. http://www.ruby-doc.org/core-2.0.0/doc/syntax/precedence_rdoc.html http://devblog.avdi.org/2010/08/02/using-and-and-or-in-ruby/ http://ruby-doc.com/docs/ProgrammingRuby/html/tut_expressions.html#UG https://www.tinfoilsecurity.com/blog/ruby-demystied-and-vs http://ruby-doc.org/docs/keywords/1.9/Object.html#method-i-and http://blog.revathskumar.com/2013/05/short-circuit-evaluation-in-ruby.html</p>