Sunday, February 22, 2015

A note on strings and Groovy methods

Just a very brief post about Groovy methods and using strings both in the method name and in the method call.

Firstly, you can use sentences for method names. Double and single quotes work but you can’t use GStrings and interpolation:

def "check the temperature in Brisbane"() {
    return 31
}

def city = 'Brisbane'
assert "check the temperature in $city"() == 31

Secondly, as that previous assert hints at, it’s possible to call a method using strings and interpolation:

def runProjectX() {

}

def method = 'runProjectX'
"$method"()

That’s all - just a quick one.