Bird
0
0

Why must block parameters be enclosed in vertical bars | | in Ruby?

hard📝 Conceptual Q10 of 15
Ruby - Blocks, Procs, and Lambdas

Why must block parameters be enclosed in vertical bars | | in Ruby?

ATo clearly separate block parameters from block body.
BTo declare global variables inside the block.
CTo indicate the block will return a value.
DTo define the block's return type explicitly.
Step-by-Step Solution
Solution:
  1. Step 1: Understand block parameter syntax purpose

    Vertical bars mark the start and end of block parameters, separating them from code.
  2. Step 2: Eliminate incorrect options

    Options about global variables, return values, or types are incorrect.
  3. Final Answer:

    To clearly separate block parameters from block body. -> Option A
  4. Quick Check:

    Vertical bars separate parameters from block code [OK]
Quick Trick: Vertical bars | | separate parameters from block code [OK]
Common Mistakes:
  • Thinking vertical bars declare variables globally
  • Assuming vertical bars affect return values
  • Confusing with type declarations

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes