// this is just intended to give a little more OOP structure to a script. // put most code inside of run(), plus class variables and methods. class Script { private String hello = "Hello" public Script run(Map options = [:]) { println "$hello ${options.name ?: 'World'}${shout(23)}" return this // for method chaining } private String shout(int times = 1) { return ('!' * times) } } new Script() .run() .run([name:'Crazy4Groovy']) println 'DONE'
No comments:
Post a Comment