Bird
0
0

Which of the following is the correct syntax for block parameters in Ruby?

easy📝 Syntax Q12 of 15
Ruby - Blocks, Procs, and Lambdas

Which of the following is the correct syntax for block parameters in Ruby?

array.each do ?
A[item] puts item
B(item) puts item
C|item| puts item
D{item} puts item
Step-by-Step Solution
Solution:
  1. Step 1: Recall block parameter syntax

    Block parameters are placed inside vertical bars | | after do or {.
  2. Step 2: Match syntax with options

    Only |item| puts item uses |item| which is the correct syntax for block parameters.
  3. Final Answer:

    |item| puts item -> Option C
  4. Quick Check:

    Block parameters use | | [OK]
Quick Trick: Block parameters always go inside | | after do or { [OK]
Common Mistakes:
  • Using parentheses () instead of | |
  • Using curly braces {} for parameters
  • Using square brackets [] for parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes