在下面列出的第一種方法中,使用方法在我看來很像:ins是一個實例變量,attr是爲ins提供getter和setter的方法。我不確定的是@ins << lambda
的功能。此代碼中@ins << lambda`的用途是什麼?
module Rack
class Builder
attr :ins
def use(middleware, *args, &block)
middleware.instance_variable_set "@rack_builder", self
def middleware.rack_builder
@rack_builder
end
@ins << lambda { |app|
middleware.new(app, *args, &block)
}
end
def run(app)
klass = app.class
klass.instance_variable_set "@rack_builder", self
def klass.rack_builder
@rack_builder
end
@ins << app #lambda { |nothing| app }
end
def leaf_app
ins.last
end
end
end