Bird
0
0

Identify the error in this Ruby code:

medium📝 Debug Q6 of 15
Ruby - Concurrent Programming
Identify the error in this Ruby code:
thread = Thread.new do
  puts "Running"
end
thread.wait
AThread.new requires a parameter to start.
BThread cannot print inside a block.
CBlock syntax is incorrect for Thread.new.
DMethod 'wait' does not exist for Thread objects.
Step-by-Step Solution
Solution:
  1. Step 1: Check method usage on Thread

    Ruby Thread class does not have a method named wait. The correct method to wait is join.
  2. Step 2: Verify other code parts

    Thread.new syntax and block are correct; printing inside thread is allowed.
  3. Final Answer:

    Method 'wait' does not exist for Thread objects. -> Option D
  4. Quick Check:

    Use join, not wait, to wait for threads [OK]
Quick Trick: Use thread.join, not thread.wait, to wait for threads [OK]
Common Mistakes:
  • Using non-existent thread methods like wait
  • Confusing thread creation syntax
  • Thinking threads can't print output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes