Reputation: 147
I am absolutely new to groovy and I am trying to understand an existing groovy code to make changes. The code is a small groovy script like so:
package myapp.confg
appName = "myapp"
appVersion = "103"
tags {
ags = "${myapp}"
}
I understand that appName
and appVersion
are global variables. However I cannot understand what tags
is. Its not a closure and its not a map. Any ideas what this may be? Is it some way of creating a named scope? How can I access the value of ags
from outside the tags
scope?
Upvotes: 1
Views: 103
Reputation: 1195
This can be a method with a Closure in the last parameter, and this is very common in Groovy to use the last parameter in a method as a Closure
, this comes very handy to build a DSL (Delegation...) like so:
// Example 1
def t(Closure c){
println('from Closure')
}
t {
// do something
}
// Example 2
def t2(int i, int j, Closure c){
print("closure with: $i, $j")
}
t2(1,2) {
// do other something
}
More examples can be found in the doc for Delegation.
Upvotes: 1