SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Downloaden Sie, um offline zu lesen
and
(and	
  &&)	
  	
   (or	
  ||) operators
	
  

@DonSchado | 15.01.2014
and
(and	
  &&)	
  	
   (or	
  ||) operators
	
  
olic boolean
nglish and symb
e

@DonSchado | 15.01.2014
Quiztime!!! o/
foo	
  =	
  true	
  &&	
  "bar"
foo	
  =	
  ?

#=>	
  ?
foo	
  =	
  true	
  &&	
  "bar"
foo	
  =	
  "bar"

#=>	
  "bar"
foo	
  =	
  true	
  &&	
  "bar"

#=>	
  "bar"

foo	
  =	
  "bar"

foo	
  =	
  true	
  and	
  "bar"
foo	
  =	
  ?

#=>	
  ?
foo	
  =	
  true	
  &&	
  "bar"

#=>	
  "bar"

foo	
  =	
  "bar"

foo	
  =	
  true	
  and	
  "bar"
foo	
  =	
  true

#=>	
  "bar"
foo	
  =	
  42	
  &&	
  foo	
  *	
  2
foo	
  =	
  ?

#=>	
  ?
foo	
  =	
  42	
  &&	
  foo	
  *	
  2

#=>	
  NoMethodError:	
  
undefined	
  method	
  `*'	
  for	
  nil:NilClass

foo	
  =	
  nil
foo	
  =	
  42	
  &&	
  foo	
  *	
  2

#=>	
  NoMethodError:	
  
undefined	
  method	
  `*'	
  for	
  nil:NilClass

foo	
  =	
  nil

foo	
  =	
  42	
  and	
  foo	
  *	
  2
foo	
  =	
  ?

#=>	
  ?
foo	
  =	
  42	
  &&	
  foo	
  *	
  2

#=>	
  NoMethodError:	
  
undefined	
  method	
  `*'	
  for	
  nil:NilClass

foo	
  =	
  nil

foo	
  =	
  42	
  and	
  foo	
  *	
  2
foo	
  =	
  42

#=>	
  84
short-circuit evaluation & precedence
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 first
argument does not suffice 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
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 first
argument does not suffice 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	
  &&	
  :bar

#=>	
  :bar
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 first
argument does not suffice 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	
  &&	
  :bar
if	
  :foo
	
  :bar
end

#=>	
  :bar
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 first
argument does not suffice 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	
  &&	
  :bar

#=>	
  :bar

if	
  :foo
	
  :bar
end

:foo	
  ||	
  :bar

#=>	
  :foo
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 first
argument does not suffice 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	
  &&	
  :bar

#=>	
  :bar

if	
  :foo
	
  :bar
end

:foo	
  ||	
  :bar
if	
  :foo
	
  :foo
else
	
  :bar
end

#=>	
  :foo
precedence

high

!, ~, unary +
**
unary *, /, %
+, <<, >>
&
|, ^
>, >=, <, <=
<=>, ==, ===, !=, =~, !~
&&
||
.., ...
?, :
modifier-rescue
=, +=, -=, etc.
defined?
not
or, and
modifier-if, *-unless, *-while, *-until
{ } blocks

High precedence operations happen
before low precedence operations.

http://www.ruby-doc.org/core-2.0.0/doc/syntax/precedence_rdoc.html

low
precedence

high

!, ~, unary +
**
unary *, /, %
+, <<, >>
&
|, ^
>, >=, <, <=
<=>, ==, ===, !=, =~, !~
&&
||
.., ...
?, :
modifier-rescue
=, +=, -=, etc.
defined?
not
or, and
modifier-if, *-unless, *-while, *-until
{ } blocks

High precedence operations happen
before low precedence operations.

≠ just to make life
more interesting

=

http://www.ruby-doc.org/core-2.0.0/doc/syntax/precedence_rdoc.html

low
precedence

high

!, ~, unary +
**
unary *, /, %
+, <<, >>
&
|, ^
>, >=, <, <=
<=>, ==, ===, !=, =~, !~
&&
||
.., ...
?, :
modifier-rescue
=, +=, -=, etc.
defined?
not
or, and
modifier-if, *-unless, *-while, *-until
{ } blocks

High precedence operations happen
before low precedence operations.
foo	
  =	
  (true	
  &&	
  "bar")

(foo	
  =	
  true)	
  and	
  "bar"

≠ just to make life
more interesting

=

http://www.ruby-doc.org/core-2.0.0/doc/syntax/precedence_rdoc.html

low
precedence

high

!, ~, unary +
**
unary *, /, %
+, <<, >>
&
|, ^
>, >=, <, <=
<=>, ==, ===, !=, =~, !~
&&
||
.., ...
?, :
modifier-rescue
=, +=, -=, etc.
defined?
not
or, and
modifier-if, *-unless, *-while, *-until
{ } blocks

High precedence operations happen
before low precedence operations.
foo	
  =	
  (true	
  &&	
  "bar")

(foo	
  =	
  true)	
  and	
  "bar"

≠ just to make life
more interesting

foo	
  =	
  (42	
  &&	
  (foo	
  *	
  2))

(foo	
  =	
  42)	
  and	
  (foo	
  *	
  2)

=

http://www.ruby-doc.org/core-2.0.0/doc/syntax/precedence_rdoc.html

low
http://ruby-doc.org/docs/keywords/1.9/Object.html#method-i-and
http://ruby-doc.org/docs/keywords/1.9/Object.html#method-i-or
don‘t be afraid of and and or
• not be suitable for regular boolean logic
• use them for readable control-flow scenarios
• don‘t mix them up with && and || in the same expression
examples
raise	
  "Not	
  ready!"	
  unless	
  ready_to_rock?
examples
raise	
  "Not	
  ready!"	
  unless	
  ready_to_rock?

=>

ready_to_rock?	
  or	
  raise	
  "Not	
  ready!"
examples
raise	
  "Not	
  ready!"	
  unless	
  ready_to_rock?
next	
  if	
  widget	
  =	
  widgets.pop

=>

ready_to_rock?	
  or	
  raise	
  "Not	
  ready!"
examples
raise	
  "Not	
  ready!"	
  unless	
  ready_to_rock?

=>

ready_to_rock?	
  or	
  raise	
  "Not	
  ready!"

next	
  if	
  widget	
  =	
  widgets.pop

=>

widget	
  =	
  widgets.pop	
  and	
  next
examples
raise	
  "Not	
  ready!"	
  unless	
  ready_to_rock?

=>

ready_to_rock?	
  or	
  raise	
  "Not	
  ready!"

next	
  if	
  widget	
  =	
  widgets.pop

=>

widget	
  =	
  widgets.pop	
  and	
  next

@post	
  =	
  Post.find_by_name(name)	
  and	
  @post.publish!
examples
raise	
  "Not	
  ready!"	
  unless	
  ready_to_rock?

=>

ready_to_rock?	
  or	
  raise	
  "Not	
  ready!"

next	
  if	
  widget	
  =	
  widgets.pop

=>

widget	
  =	
  widgets.pop	
  and	
  next

@post	
  =	
  Post.find_by_name(name)	
  and	
  @post.publish!

foo	
  =	
  get_foo	
  or	
  raise	
  "Could	
  not	
  find	
  foo!"
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-demystified-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

Weitere ähnliche Inhalte

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 

Kürzlich hochgeladen (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

English and symbolic boolean operators in Ruby

  • 1. and (and  &&)     (or  ||) operators   @DonSchado | 15.01.2014
  • 2. and (and  &&)     (or  ||) operators   olic boolean nglish and symb e @DonSchado | 15.01.2014
  • 4. foo  =  true  &&  "bar" foo  =  ? #=>  ?
  • 5. foo  =  true  &&  "bar" foo  =  "bar" #=>  "bar"
  • 6. foo  =  true  &&  "bar" #=>  "bar" foo  =  "bar" foo  =  true  and  "bar" foo  =  ? #=>  ?
  • 7. foo  =  true  &&  "bar" #=>  "bar" foo  =  "bar" foo  =  true  and  "bar" foo  =  true #=>  "bar"
  • 8. foo  =  42  &&  foo  *  2 foo  =  ? #=>  ?
  • 9. foo  =  42  &&  foo  *  2 #=>  NoMethodError:   undefined  method  `*'  for  nil:NilClass foo  =  nil
  • 10. foo  =  42  &&  foo  *  2 #=>  NoMethodError:   undefined  method  `*'  for  nil:NilClass foo  =  nil foo  =  42  and  foo  *  2 foo  =  ? #=>  ?
  • 11. foo  =  42  &&  foo  *  2 #=>  NoMethodError:   undefined  method  `*'  for  nil:NilClass foo  =  nil foo  =  42  and  foo  *  2 foo  =  42 #=>  84
  • 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 first argument does not suffice 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 first argument does not suffice 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  &&  :bar #=>  :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 first argument does not suffice 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  &&  :bar if  :foo  :bar end #=>  :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 first argument does not suffice 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  &&  :bar #=>  :bar if  :foo  :bar end :foo  ||  :bar #=>  :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 first argument does not suffice 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  &&  :bar #=>  :bar if  :foo  :bar end :foo  ||  :bar if  :foo  :foo else  :bar end #=>  :foo
  • 18. precedence high !, ~, unary + ** unary *, /, % +, <<, >> & |, ^ >, >=, <, <= <=>, ==, ===, !=, =~, !~ && || .., ... ?, : modifier-rescue =, +=, -=, etc. defined? not or, and modifier-if, *-unless, *-while, *-until { } blocks High precedence operations happen before low precedence operations. http://www.ruby-doc.org/core-2.0.0/doc/syntax/precedence_rdoc.html low
  • 19. precedence high !, ~, unary + ** unary *, /, % +, <<, >> & |, ^ >, >=, <, <= <=>, ==, ===, !=, =~, !~ && || .., ... ?, : modifier-rescue =, +=, -=, etc. defined? not or, and modifier-if, *-unless, *-while, *-until { } blocks High precedence operations happen before low precedence operations. ≠ just to make life more interesting = http://www.ruby-doc.org/core-2.0.0/doc/syntax/precedence_rdoc.html low
  • 20. precedence high !, ~, unary + ** unary *, /, % +, <<, >> & |, ^ >, >=, <, <= <=>, ==, ===, !=, =~, !~ && || .., ... ?, : modifier-rescue =, +=, -=, etc. defined? not or, and modifier-if, *-unless, *-while, *-until { } blocks High precedence operations happen before low precedence operations. foo  =  (true  &&  "bar") (foo  =  true)  and  "bar" ≠ just to make life more interesting = http://www.ruby-doc.org/core-2.0.0/doc/syntax/precedence_rdoc.html low
  • 21. precedence high !, ~, unary + ** unary *, /, % +, <<, >> & |, ^ >, >=, <, <= <=>, ==, ===, !=, =~, !~ && || .., ... ?, : modifier-rescue =, +=, -=, etc. defined? not or, and modifier-if, *-unless, *-while, *-until { } blocks High precedence operations happen before low precedence operations. foo  =  (true  &&  "bar") (foo  =  true)  and  "bar" ≠ just to make life more interesting foo  =  (42  &&  (foo  *  2)) (foo  =  42)  and  (foo  *  2) = http://www.ruby-doc.org/core-2.0.0/doc/syntax/precedence_rdoc.html low
  • 24. don‘t be afraid of and and or • not be suitable for regular boolean logic • use them for readable control-flow scenarios • don‘t mix them up with && and || in the same expression
  • 25. examples raise  "Not  ready!"  unless  ready_to_rock?
  • 26. examples raise  "Not  ready!"  unless  ready_to_rock? => ready_to_rock?  or  raise  "Not  ready!"
  • 27. examples raise  "Not  ready!"  unless  ready_to_rock? next  if  widget  =  widgets.pop => ready_to_rock?  or  raise  "Not  ready!"
  • 28. examples raise  "Not  ready!"  unless  ready_to_rock? => ready_to_rock?  or  raise  "Not  ready!" next  if  widget  =  widgets.pop => widget  =  widgets.pop  and  next
  • 29. examples raise  "Not  ready!"  unless  ready_to_rock? => ready_to_rock?  or  raise  "Not  ready!" next  if  widget  =  widgets.pop => widget  =  widgets.pop  and  next @post  =  Post.find_by_name(name)  and  @post.publish!
  • 30. examples raise  "Not  ready!"  unless  ready_to_rock? => ready_to_rock?  or  raise  "Not  ready!" next  if  widget  =  widgets.pop => widget  =  widgets.pop  and  next @post  =  Post.find_by_name(name)  and  @post.publish! foo  =  get_foo  or  raise  "Could  not  find  foo!"