Bird
0
0

Which of the following is the correct syntax to pass a block to a method in Ruby?

easy📝 Syntax Q12 of 15
Ruby - Blocks, Procs, and Lambdas
Which of the following is the correct syntax to pass a block to a method in Ruby?
Amethod_name { |param| puts param }
Bmethod_name (|param| puts param)
Cmethod_name -> { puts param }
Dmethod_name [|param| puts param]
Step-by-Step Solution
Solution:
  1. Step 1: Recognize Ruby block syntax

    Blocks are passed using curly braces {} or do..end after the method call.
  2. Step 2: Match the correct syntax

    method_name { |param| puts param } uses curly braces with a block parameter and code inside, which is correct.
  3. Final Answer:

    method_name { |param| puts param } -> Option A
  4. Quick Check:

    Curly braces or do..end define blocks [OK]
Quick Trick: Use {} or do..end after method for blocks [OK]
Common Mistakes:
  • Using parentheses instead of braces for blocks
  • Confusing lambda syntax with blocks
  • Using square brackets for blocks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes