LoginSignup
0
0

More than 5 years have passed since last update.

ConfigSlurperでClosureを読み出せた件

Last updated at Posted at 2017-03-13

言いたい事はタイトルの通りです
実際使えたコード例を示します

def cs=""
cs+="value={->"
cs+="println 'This is from Closure'"
cs+="}"
def obj=new ConfigSlurper().parse(cs)
println "Running Closure..."
obj.value()

この場合、プログラム終了時点でのcsの値は

value={->println 'This is from Closure'}

となります。\nは無いので改行はありません。

出力はもちろん

Running Closure...
This is from Closure

こうなります。
println "Running Closure..."は、Closure内部で実行されていることを確認するために入れています。
ideoneで出力を示そうと思ったのですが、なぜか使えませんでした
ConfigSlurperで一風変わった設定ファイルが作れそうですね

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0