Bird
0
0

Which of the following is the correct syntax for a Ruby block using curly braces?

easy📝 Syntax Q3 of 15
Ruby - Blocks, Procs, and Lambdas
Which of the following is the correct syntax for a Ruby block using curly braces?
Aarray.each do |item| puts item end
Barray.each (|item| { puts item })
Carray.each { |item| puts item }
Darray.each { |item| puts item end }
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct curly brace block syntax

    Curly brace blocks use {} with the block parameter between pipes and the block code inside.
  2. Step 2: Check each option

    array.each { |item| puts item } correctly uses { |item| puts item }. array.each do |item| puts item end uses do..end, not curly braces. array.each (|item| { puts item }) has wrong parentheses and braces. array.each { |item| puts item end } mixes braces with do..end incorrectly.
  3. Final Answer:

    array.each { |item| puts item } -> Option C
  4. Quick Check:

    Curly brace block syntax = B [OK]
Quick Trick: Curly braces wrap block code with pipes for parameters [OK]
Common Mistakes:
  • Mixing do..end with curly braces
  • Wrong placement of pipes
  • Using parentheses incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes