tags:

views:

88

answers:

1

My goal is to write this:

println "this should be 3: ($1+2)" //this is invalid groovy, it won't run

Yet this is valid in ruby. Is there a way I can put statements that will eval inside a string or must I use complete variables names? I am basically looking for the Ruby equivalent of:

puts "this shoud be 3: #{1+2}" #this is valid ruby
+5  A: 

This is what you need

println "this should be 3: ${1+2}"

If the code being evaluated is a variable name or a GPath expression you can omit the curly braces, e.g.

def foo = "bar"
println "The value is $foo"

But if you want to be on the safe side, always put the code inside ${}

Don