Module 01 Β· Ruby Basics β Lesson 4 of 6 Β· ~11 min
Conditionals the Ruby Way
if / elsif / else / end β no braces, no parens
Swift wraps a condition in parens and a body in braces. Python drops the parens but keeps significant indentation with a colon. Ruby drops BOTH parens and braces β the block is closed with an explicit end keyword instead:
rating = 4.9 if rating >= 4.8 puts "top rated" elsif rating >= 4.0 puts "solid" else puts "needs reviews" end
elsif β no second e, easy to misspell once and never again. Indentation (2 spaces, by convention) is purely cosmetic here, unlike Python β Ruby knows the block ends at end, not by dedenting.