ruby - Rack::Builder 'to_app' method comprehension -


i saw railscast #151. in video, rack's snippet presented. corresponds rack::builder module. i'm missing in to_app method:

 def to_app   app = @map ? generate_map(@run, @map) : @run   fail "missing run or map statement" unless app   @use.reverse.inject(app) { |a,e| e[a] } end 

could explain last line of method , does? know inject uses accumulator variable , element variable. don't understand why array subscription e[a].

in case, [] not array access. it's 1 way call lambda or proc, equivalent e.call(a). (see documentation.) if @ use method, @use variable array of lambdas. code running through each middleware (and/or mapping) in reverse order, , calling each lambda app argument. how build app bit bit.


Comments