Bird
0
0

Identify the error in this Ruby Ractor code:

medium📝 Debug Q6 of 15
Ruby - Concurrent Programming
Identify the error in this Ruby Ractor code:
r = Ractor.new do
  y = 10
end
puts r.take + y
ACannot call <code>take</code> on a Ractor
BRactor block must return a value explicitly
CVariable <code>y</code> is undefined outside the Ractor
DRactor cannot assign variables inside the block
Step-by-Step Solution
Solution:
  1. Step 1: Check variable scope

    Variable y is local to the Ractor block and not accessible outside.
  2. Step 2: Analyze usage

    Trying to use y outside causes a NameError.
  3. Final Answer:

    Variable y is undefined outside the Ractor -> Option C
  4. Quick Check:

    Ractor variables are isolated [OK]
Quick Trick: Variables inside Ractor block aren't accessible outside [OK]
Common Mistakes:
  • Assuming Ractor variables are global
  • Thinking take cannot be called on Ractor
  • Believing explicit return is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes