Bird
0
0

Which of the following is the correct syntax for using inline unless in Ruby?

easy📝 Syntax Q12 of 15
Ruby - Control Flow
Which of the following is the correct syntax for using inline unless in Ruby?
Aputs "No" unless false
Bputs "No" unless
Cputs "No"unless (false)
Dputs "No" unless: false
Step-by-Step Solution
Solution:
  1. Step 1: Recall inline unless syntax

    Inline unless requires a condition after the keyword, like unless false.
  2. Step 2: Check each option

    puts "No" unless false is valid syntax. puts "No"unless (false) puts "No"unless (false) is invalid due to missing space after the string literal. Options B and D are incomplete or invalid.
  3. Final Answer:

    puts "No" unless false -> Option A
  4. Quick Check:

    Inline unless needs a condition after it [OK]
Quick Trick: Inline unless needs a condition right after it [OK]
Common Mistakes:
MISTAKES
  • Omitting the condition after unless
  • Using colon instead of space
  • Adding unnecessary parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes