Bird
0
0

You want to compose three Procs:

hard📝 Application Q9 of 15
Ruby - Functional Patterns in Ruby
You want to compose three Procs:
p1 = Proc.new { |x| x + 1 }
p2 = Proc.new { |y| y * 2 }
p3 = Proc.new { |z| z - 3 }

Which expression correctly composes them so the input is first processed by p1, then p2, then p3?
Ap1 >> p2 >> p3
Bp3 >> p2 >> p1
Cp3 << p2 << p1
Dp1 << p2 << p3
Step-by-Step Solution
Solution:
  1. Step 1: Understand chaining multiple Procs

    Composition is left to right: p1 >> p2 >> p3 applies p1, then p2, then p3.
  2. Step 2: Verify other options

    Options with << reverse order or wrong chaining.
  3. Final Answer:

    p1 >> p2 >> p3 -> Option A
  4. Quick Check:

    Chain Procs left to right with >> [OK]
Quick Trick: Use >> repeatedly to chain multiple Procs [OK]
Common Mistakes:
  • Using << which reverses order
  • Chaining in wrong sequence
  • Mixing << and >> operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes