$LOAD_PATH.unshift('../../lib', __FILE__) require "quickl" $wrappers = [] def wrap(filter, &block) $wrappers << [ filter, block ] end def build_wrapper(command, filter, continuation) lambda{|cont| if !filter || command.instance_eval(&filter) command.instance_exec(continuation, &b) else continuation.call end } end def execute(command, &block) first = build_wrapper(command, *$wrappers.first) c = $wrappers[1..-1].inject(first){|cont,wrapper| build_wrapper(command, *wrapper) } c.call(block) end wrap(lambda{ true }){|cont| puts "wrap 1" cont.call puts "end wrap 1" } wrap(lambda{ true }){|cont| puts "wrap 2" cont.call puts "end wrap 2" } execute(self){ puts "hello" }