2

Cucumber-JVM の Groovy ステップ定義を実装しています。次のステップで n 回繰り返すことができるように、ステップがそれ自体を格納できるようにしたいと考えています。

Given(~'the (\\S+) is in the blender') { String thing ->
    // do stuff...
    context.repeatable = self.curry(thing)
}

上記のコードで「自己」とは何ですか?

「これ」は囲んでいるオブジェクトを指すため使用できません (この場合、それが何であれ、スクリプトかもしれません)。

4

2 に答える 2

1

はClosurecurryクラスのメソッドであるため、カリーの直接呼び出しはクロージャーに適用されます。

def context

test = { String thing ->
    context = curry(thing)
    thing.toUpperCase() 
}

test('hello')
println context.call()
test('world')
println context.call()

=>

HELLO
WORLD

または匿名:

def context

['test'].each { String thing ->
    context = curry(thing)
    thing.toUpperCase() 
}

println context.call()

=>

TEST
于 2013-03-29T20:37:49.237 に答える
0

参照されていないcurryメソッドを使用して、受信したパラメーターを渡すことができます。

clos = { String text ->
    if (text) {
        println "text=$text"
        a = curry null
        a()
    } else {
        println "done"
    }
}

clos "closure text"

印刷します:

text=closure text
done

アップデート

次のものも使用できますclone()

closure = {
    def clone = clone()
}
于 2013-03-29T19:50:14.587 に答える