Bird
0
0

Which of the following is the correct syntax to compose two Procs p1 and p2 in Ruby?

easy📝 Syntax Q12 of 15
Ruby - Functional Patterns in Ruby
Which of the following is the correct syntax to compose two Procs p1 and p2 in Ruby?
Acombined = p1 >> p2
Bcombined = p1 >>> p2
Ccombined = p1 << p2
Dcombined = p1 >> p2.call
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct Proc composition operator

    The operator to compose Procs is >>, which is written as >> but in Ruby code it is >> (two greater-than signs).
  2. Step 2: Check each option

    combined = p1 >> p2 uses >> correctly. combined = p1 >>> p2 uses three > which is invalid. combined = p1 << p2 uses << which is not for composition. combined = p1 >> p2.call calls p2 immediately, which is wrong.
  3. Final Answer:

    combined = p1 >> p2 -> Option A
  4. Quick Check:

    Proc composition syntax = p1 >> p2 [OK]
Quick Trick: Use exactly two > signs to compose Procs [OK]
Common Mistakes:
  • Using >>> instead of >>
  • Using << instead of >>
  • Calling Proc instead of composing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes