Recall & Review
beginner
What is the inline if modifier form in Ruby?
It is a way to write an if statement at the end of a line, like:
puts "Hello" if condition. The code before if runs only if the condition is true.Click to reveal answer
beginner
How does the inline unless modifier form work in Ruby?
It runs the code before
unless only if the condition is false. For example: puts "No" unless condition prints "No" when the condition is false.Click to reveal answer
beginner
Rewrite this code using inline if modifier:<br>
if age >= 18 puts "Adult" end
puts "Adult" if age >= 18
Click to reveal answer
beginner
What is the difference between inline if and inline unless?
Inline if runs code when the condition is true. Inline unless runs code when the condition is false. They are opposites.
Click to reveal answer
intermediate
Can you use inline if and unless with multiple statements?
No, inline if/unless works best with single statements. For multiple lines, use regular if/unless blocks.
Click to reveal answer
What does this Ruby code do?<br>
puts "Go" if ready
✗ Incorrect
The code prints "Go" only when the condition after if (ready) is true.
What will this code print?<br>
puts "Stop" unless movingif moving is false.
✗ Incorrect
The code prints "Stop" only if the condition after unless (moving) is false.
Which is the correct inline if syntax?
✗ Incorrect
The inline if modifier places the condition after the statement: puts "Yes" if condition.
Can you write multiple statements after an inline if?
✗ Incorrect
Inline if is meant for single statements only. Use regular if blocks for multiple statements.
What does this code do?<br>
puts "Ready" unless not_ready
✗ Incorrect
The code prints "Ready" only if the condition after unless (not_ready) is false.
Explain how the inline if modifier works in Ruby and give a simple example.
Think about writing an if statement at the end of a line.
You got /3 concepts.
Describe the difference between inline if and inline unless modifiers in Ruby.
Focus on when the code runs depending on the condition.
You got /3 concepts.