Bird
0
0

Which of the following is the correct syntax to use a range pattern in a Ruby case statement?

easy📝 Syntax Q3 of 15
Ruby - Control Flow
Which of the following is the correct syntax to use a range pattern in a Ruby case statement?
Acase x; in 1..5 then puts 'Yes'; end
Bcase x; when in 1..5 then puts 'Yes'; end
Ccase x; in (1..5) puts 'Yes'; end
Dcase x; in 1-5 then puts 'Yes'; end
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct case with in syntax

    The correct syntax is case variable; in pattern then action; end.
  2. Step 2: Evaluate each option

    case x; in 1..5 then puts 'Yes'; end matches this syntax correctly. case x; when in 1..5 then puts 'Yes'; end mixes when and in incorrectly. case x; in (1..5) puts 'Yes'; end misses then. case x; in 1-5 then puts 'Yes'; end uses invalid range syntax.
  3. Final Answer:

    case x; in 1..5 then puts 'Yes'; end -> Option A
  4. Quick Check:

    Use in with then for pattern matching [OK]
Quick Trick: Use in pattern then inside case [OK]
Common Mistakes:
  • Mixing when and in
  • Omitting then
  • Using invalid range syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes