Bird
0
0

What does the inline modifier if do in Ruby?

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

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

    In puts 'Hi' if condition, 'Hi' prints only if condition is true.
  3. Final Answer:

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

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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes