【发布时间】:2016-02-22 13:28:09
【问题描述】:
我尝试构建一个小型 DSL,但是我不明白下面的执行顺序。
DSL 有一个声明为summarize tests of 'me'
我的 Groovy 解释脚本是:
def tests = {
[of: { who ->
println "IN CLOSURE"
"HALLO" // dummy value for testing
}]
}
def summarize(Closure c) {
println "SUMMARIZE - CALL CLOSURE"
def f = c()
println "SUMMARIZE - CALL CLOSURE"
println "RESULT $f"
f
}
我的调用脚本有
def g = summarize tests of 'me'
println g
输出是
SUMMARIZE - CALL CLOSURE
SUMMARIZE - CALL CLOSURE
RESULT [of:com.github.groovyclient.TestRailClient$_closure1$_closure13@470f1802]
IN CLOSURE
HALLO
我实际上想在 summarize 方法中已经有 tests 闭包的结果,但似乎还没有调用内部闭包 - 在那之后发生了什么魔术,所以脚本确实有结果正确吗?
谁能解释一下,为什么是执行顺序?我怎样才能在summarize 方法中检索HALLO?
感谢您的帮助
【问题讨论】: