title: Simple way to dynamically replace placeholder with value at Groovy strings
body: <p>I'm trying to find laconic and efficient way to replace placeholders with values at the Groovy Strings. But I can't find convenient solution for 2 cases: </p>
  
  <ol>
  <li>When String with the placeholder and the value are defined at different classes.</li>
  <li><p>When the String is passed as argument to a method, and should be replaced with local's variable value. Here is the illustration of 2 approaches I have tried:</p>
  
  <pre><code>  class A {
        static def strPlaceHolder = 'token = ${tokenValue}';
        static def strRefPlaceHolder = "token = ${-&gt;tokenRef}";
    }
  
    class B {
        def tokenRef = "token reference as field";
  
        void parseGString(GString str) {
            println str; //fails here. No property tokenRef for class: A. Though I've expected that "this" is B
        }
  
        void parseString(String str) {
            def tokenValue = "token value as local variable";
            println str; //I know why it doesn't work as required. But how to make something similar
        }
  
    }
  
    new B().parseString(A.strPlaceHolder); //token = ${tokenValue}
    new B().parseGString(A.strRefPlaceHolder); //fails, 
  </code></pre></li>
  </ol>