Bird
0
0

Which of these is a valid pattern to match a number between 10 and 20 inclusive in a Ruby case statement?

easy📝 Conceptual Q2 of 15
Ruby - Control Flow
Which of these is a valid pattern to match a number between 10 and 20 inclusive in a Ruby case statement?
Ain 10...20 then puts 'Matched'
Bwhen 10..20 then puts 'Matched'
Cin 10..20 then puts 'Matched'
Din 10-20 then puts 'Matched'
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct range syntax in Ruby

    Ruby uses two dots .. for inclusive ranges, so 10..20 includes 20.
  2. Step 2: Check each option's syntax

    in 10..20 then puts 'Matched' uses 10..20 correctly. when 10..20 then puts 'Matched' incorrectly uses when instead of in. in 10-20 then puts 'Matched' uses invalid syntax. in 10...20 then puts 'Matched' uses exclusive range 10...20 which excludes 20.
  3. Final Answer:

    in 10..20 then puts 'Matched' -> Option C
  4. Quick Check:

    Range syntax with two dots = inclusive range [OK]
Quick Trick: Use two dots for inclusive ranges in patterns [OK]
Common Mistakes:
  • Using single dot or dash instead of two dots
  • Confusing inclusive and exclusive ranges
  • Using `when` instead of `in`

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes