I came across this code:
squareIt = Proc.new do |x| x * x end doubleIt = Proc.new do |x| x + x end def compose proc1, proc2 Proc.new do |x| proc2.call(proc1.call(x)) end end doubleThenSquare = compose(doubleIt, squareIt) squareThenDouble = compose(squareIt, doubleIt) doubleThenSquare.call(5) squareThenDouble.call(5) doubleThenSquare is called with 5. doubleThenSquare is equal to the return value of compose, which has its two parameters doubleIt and squareIt passed.
I don't see how 5 is passed all its way into the different procs Proc.new do |x|. How does it know what x is in each case?