Bird
0
0

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

easy📝 Syntax Q12 of 15
Ruby - Error Handling
Which of the following is the correct syntax for using the rescue modifier inline in Ruby?
Aresult = some_method rescue fallback_value
Bresult = rescue some_method fallback_value
Cresult = some_method ? rescue fallback_value
Dresult = some_method else rescue fallback_value
Step-by-Step Solution
Solution:
  1. Step 1: Recall the rescue modifier syntax

    The rescue modifier is placed after an expression, followed by the fallback value, like expression rescue fallback.
  2. Step 2: Match with options

    Only result = some_method rescue fallback_value matches this syntax correctly: result = some_method rescue fallback_value.
  3. Final Answer:

    result = some_method rescue fallback_value -> Option A
  4. Quick Check:

    Correct rescue modifier syntax = result = some_method rescue fallback_value [OK]
Quick Trick: Rescue modifier goes after expression, then fallback [OK]
Common Mistakes:
  • Placing rescue before the expression
  • Using question marks or else with rescue modifier
  • Confusing rescue modifier with rescue block

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes