Bird
0
0

Which of these is the correct syntax to create a new thread in Ruby?

easy📝 Syntax Q3 of 15
Ruby - Concurrent Programming
Which of these is the correct syntax to create a new thread in Ruby?
Anew Thread { puts 'Hello' }
BThread.new { puts 'Hello' }
CThread.create { puts 'Hello' }
DThread.start puts 'Hello'
Step-by-Step Solution
Solution:
  1. Step 1: Recall Ruby thread creation syntax

    Ruby uses Thread.new with a block to start a new thread.
  2. Step 2: Check each option

    Only Thread.new { puts 'Hello' } uses Thread.new with a block correctly.
  3. Final Answer:

    Thread.new { puts 'Hello' } -> Option B
  4. Quick Check:

    Thread creation syntax = Thread.new { ... } [OK]
Quick Trick: Use Thread.new with a block to start threads [OK]
Common Mistakes:
  • Using Thread.create instead of Thread.new
  • Omitting curly braces for the block
  • Using new Thread instead of Thread.new

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes