Conditionals
TruthTruth: Everything is true except for:false nilTherefore0 is true“” is true
Conditionals: ifif age > 17	puts “can vote”endif age > 17	puts “can vote”else	puts “attends school”endStatement Modifiers:do_something if x == 4Other Syntax:if x == 4 then do_something end
Conditionals: ifif age >= 21 	  puts “can drink”elsif age > 17    puts “can vote”else 	  puts “too young”end
Checking for falseif !(name == “superman”) …if not (name == “superman”) …
Unless“unless” provides us with another way of checking if a condition is false:	unless human		status = "superhero"	end	status = "superhero" unless human
Casecase superherowhen "superman"	 city = "metropolis"when "batman"	 city = "gotham_city"else			city = "central_city"end
Case Refactoringcity = case superherowhen "superman"		 "metropolis"when "batman"		 "gotham_city"else			 "central_city"end
Casecase numwhen 1puts "one"when 2..5puts "that is small"else	puts "pretty big"end
Casecase namewhen "Sarah"puts "awesome"when /Mr.*/puts "formal guy"else	puts "whatever"end
Casecase args		when String			puts "Got a String"  	when Array			puts "Got an Array” 	when Hash			puts "Got a Hash"end

More Related Content

PPS
It’s reality
ODP
Search and Seizure / Assumptions
PPTX
Transparency Wins
KEY
International Web Application Development
KEY
Full text search adventures
KEY
Crafting Software Products
KEY
Rhodes Overview
PDF
Let's pretend
It’s reality
Search and Seizure / Assumptions
Transparency Wins
International Web Application Development
Full text search adventures
Crafting Software Products
Rhodes Overview
Let's pretend

More from Sarah Allen (20)

PDF
Internet security: a landscape of unintended consequences
PPTX
RTMP: how did we get to now? (Demuxed 2019)
PDF
Communication is a Technical Skill
PPTX
Improving Federal Government Services
PPTX
A Short History of Computers
PPTX
Making Software Fun
PPTX
Power of Transparency
PPTX
Designing for Fun
PDF
Ruby in the US Government for Ruby World Conference
PDF
Identities of Dead People
PDF
3 Reasons Not to Use Ruby
PDF
Ruby Nation: Why no haz Ruby?
PDF
Why no ruby in gov?
PDF
People Patterns or What I learned from Toastmasters
PDF
Blazing Cloud: Agile Product Development
PDF
Crowdsourced Transcription Landscape
PDF
Lessons Learned Future Thoughts
PDF
Mobile Web Video
PPTX
Elementary Computer History
PDF
Sarah Allen Computer Science Entrepreneur
Internet security: a landscape of unintended consequences
RTMP: how did we get to now? (Demuxed 2019)
Communication is a Technical Skill
Improving Federal Government Services
A Short History of Computers
Making Software Fun
Power of Transparency
Designing for Fun
Ruby in the US Government for Ruby World Conference
Identities of Dead People
3 Reasons Not to Use Ruby
Ruby Nation: Why no haz Ruby?
Why no ruby in gov?
People Patterns or What I learned from Toastmasters
Blazing Cloud: Agile Product Development
Crowdsourced Transcription Landscape
Lessons Learned Future Thoughts
Mobile Web Video
Elementary Computer History
Sarah Allen Computer Science Entrepreneur
Ad

Ruby conditionals

Editor's Notes

  • #3: Unlike some languages with the 0 and empty string! Binds more tightly than than the “not” keyword so you do need parentheses for example 1, but don’t need parentheses for example 2
  • #4: Conditionals are key to being able to make decisions in a programleft looks like every other languageparentheses are optional in ruby make sure to do ==, = is an assignment, == is a conditional testExplain putsright is a little different…people in ruby don’t like to type…english readableA statement modifier lets you move control structures at the end of an expression.
  • #5: Conditionals are key to being able to make decisions in a programleft looks like every other languageparentheses are optional in ruby make sure to do ==, = is an assignment, == is a conditional testExplain putsright is a little different…people in ruby don’t like to type…english readableA statement modifier lets you move control structures at the end of an expression.
  • #7: Unless can be awkward, especially with else. Usually you’ll want to use if for conditionals with else clauses.Occasionally unless is more readable:unless something is nil