Bird
0
0

What does the inline modifier unless do in Ruby?

easy📝 Conceptual Q2 of 15
Ruby - Control Flow
What does the inline modifier unless do in Ruby?
Example: puts 'Bye' unless condition
AIt runs the code only if the condition is true.
BIt always runs the code regardless of the condition.
CIt runs the code only if the condition is nil.
DIt runs the code only if the condition is false.
Step-by-Step Solution
Solution:
  1. Step 1: Understand inline unless modifier

    The inline unless runs the code only when the condition is false.
  2. Step 2: Apply to example

    In puts 'Bye' unless condition, 'Bye' prints only if condition is false.
  3. Final Answer:

    It runs the code only if the condition is false. -> Option D
  4. Quick Check:

    Inline unless = runs code if false [OK]
Quick Trick: Inline unless runs code only when condition is false [OK]
Common Mistakes:
  • Confusing unless with if
  • Thinking code runs when condition is true
  • Assuming code never runs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes