Bird
0
0

Why does composing Procs with the > in Ruby?

hard📝 Conceptual Q10 of 15
Ruby - Functional Patterns in Ruby
Why does composing Procs with the << operator produce different results than using >> in Ruby?
A<< causes syntax error when used with Procs
B<< is an alias for >> and behaves the same
C<< merges Procs into an array instead of composing
D<< composes Procs in reverse order, applying right Proc first
Step-by-Step Solution
Solution:
  1. Step 1: Understand << and >> operators for Procs

    >> applies left Proc then right; << applies right Proc then left.
  2. Step 2: Explain effect on composition order

    p1 << p2 means p1.call(p2.call(x)), reversing order.
  3. Final Answer:

    << composes Procs in reverse order, applying right Proc first -> Option D
  4. Quick Check:

    << reverses Proc composition order [OK]
Quick Trick: << reverses composition order vs >> [OK]
Common Mistakes:
  • Assuming << and >> behave identically
  • Thinking << causes syntax error
  • Believing << merges Procs into arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes