Bird
0
0

Which of the following is the correct way to create a Fiber in Ruby?

easy📝 Syntax Q12 of 15
Ruby - Concurrent Programming
Which of the following is the correct way to create a Fiber in Ruby?
Afiber = Fiber.start { puts 'Hello' }
Bfiber = Fiber.new { puts 'Hello' }
Cfiber = Fiber.create { puts 'Hello' }
Dfiber = Fiber.run { puts 'Hello' }
Step-by-Step Solution
Solution:
  1. Step 1: Recall Fiber creation syntax

    Ruby uses Fiber.new with a block to create a new Fiber.
  2. Step 2: Check other options

    Methods like create, start, or run do not exist for Fiber creation.
  3. Final Answer:

    fiber = Fiber.new { puts 'Hello' } -> Option B
  4. Quick Check:

    Fiber creation = Fiber.new [OK]
Quick Trick: Use Fiber.new with a block to create a Fiber [OK]
Common Mistakes:
  • Using non-existent Fiber methods like create or start
  • Forgetting to pass a block to Fiber.new
  • Confusing Fiber with Thread syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes