Complete the code to create a new thread that prints 'Hello from thread!'.
thread = Thread.[1] do puts 'Hello from thread!' end thread.join
In Ruby, Thread.new creates a new thread and starts it immediately.
Complete the code to wait for the thread to finish before continuing.
thread = Thread.new do puts 'Working in thread' end [1]
thread.join waits for the thread to finish before the main program continues.
Fix the error in the code to properly create and start a thread that prints numbers.
thread = Thread.[1] do 3.times { |i| puts i } end thread.join
The correct method to create and start a thread is Thread.new.
Fill both blanks to create a thread that prints squares of numbers from 1 to 3 and waits for it to finish.
thread = Thread.[1] do (1..3).each { |n| puts n[2]2 } end thread.join
Thread.new creates the thread, and ** is the exponent operator to square numbers.
Fill both blanks to create a thread that prints uppercase letters from an array and waits for it to finish.
letters = ['a', 'b', 'c'] thread = Thread.[1] do letters.each { |letter| puts letter.[2] } end thread.join
capitalize which only capitalizes the first letterstart which is not a Ruby method for threadsThread.new creates the thread, upcase converts letters to uppercase, and join waits for the thread to finish.